I'm currently using <a> tags with jQuery to initiate things like click events, etc.
Example is <a href="#" class="someclass">Text</a>
But I hate how the '#' makes the page jump to the top of the page. What can I do instead?
I'm currently using <a> tags with jQuery to initiate things like click events, etc.
Example is <a href="#" class="someclass">Text</a>
But I hate how the '#' makes the page jump to the top of the page. What can I do instead?
There are 4 similar ways to prevent the page from jumping to the top without any JavaScript:
Option 1:
<a href="#0">Link</a>
Option 2:
<a href="#!">Link</a>
Option 3:
<a href="#/">Link</a>
Option 4 (Not recommended):
<a href="javascript:void(0);">Link</a>
But it's better to use event.preventDefault() if you are handing the click event in jQuery.
I've always used:
<a href="#?">Some text</a>
when trying to prevent the page jump. Not sure if this is the best, but it seems to have been working well for years.
The simplest one for me was to do this.
<a href="#" onclick="return false;">Some text</a>
The reason for using JS is that most modern sites rely on it.
The <a href="#!">Link</a> and <a href="#/">Link</a> does not work if one has to click on the same input more than once.. it only takes in 1 event click for each on multiple inputs.
still the best way to go is with <a href="#">Link</a>
then,
event.preventDefault();