rabid_zombie
rabid_zombie

Reputation: 992

Noscript disable anchor tag behavior

When I disable javascript on my site, I want to prevent the default behavior of the anchor tag.

<li class="last"><a href="#" id="viewexample" class="btn btn-view">View<span>&nbsp;</span></a></li>

How can I prevent this link from jumping to the top of the page when javascript is disabled?

Upvotes: 0

Views: 938

Answers (4)

Jellicle
Jellicle

Reputation: 30206

  1. Drop the href attribute
  2. Use css to add the 'pointer' cursor
  3. Use js to add the desired behaviour to the anchor (so when js is disabled, the clicking will not do anything)

html & js:

<a onclick="document.location.href='#'">View<span>&nbsp;</span></a>

css:

a:hover {cursor:pointer;}

Upvotes: 1

Cristian Sanchez
Cristian Sanchez

Reputation: 32107

You could try:

<a href="javascript:void(0)">Link</a>

or

<a href="#noop">Link</a> <!-- #noop does not exist -->

Upvotes: 0

hugomg
hugomg

Reputation: 69934

Don't use the <a> tag at all, given it is not a real link? You could change it into a button or add events directly to the <li>s.

Upvotes: 2

user715714
user715714

Reputation:

Without the help of Javascript, since the href is pointing to #, you can't prevent it from jumping. You would have to change the # to an actual link.

Upvotes: 0

Related Questions