I can see a lot of <a href="javascript:void(0);"> on html pages. From I've read it does nothing by returning undefined. How is this different with <href="#">
3 Answers
<a href="#">link</a>
adds # to the browser url and jumps to the top of the page.
<a href="javascript:void(0);">link</a>
simply "ignores" the link click.
<a href="#" onclick="return false;">link</a>
also ignores the href.
Don't forget that in some cases javascript might be disabled (very uncommon).
# might jump to a different location in the page. Plus, it modifies the URL
4 Comments
Akshay Khandelwal
modifies the url is fine but jump is not. and here if it's just "#" then the jump is to the top of the page
Leo
huh? I'm confused, there's a bit of discrepancy in your comment. You say that jump is not fine and then that the jump is to the top of the page. I don't get it
Akshay Khandelwal
which is why we use javascript:void(0) that does not make the jump
Leo
Mate, you lost the plot...looks like you are on a different conversation
#jumps to the top of the page.