Dave's Brain

Browse - Programming Tips - How do I make a link that does nothing?

Date: 2011feb3
Platform: web

Q.  How do I make a link that does nothing?

A.  Use void(0) like this:

<a href="javascript:void(0)">a link that does nothing</a>
This will look like regular link but will not reload the current page or anything. (Unlike href=#) Now, you can use other techniques to make it do something useful. Regular javaScript:
<a href="javascript:void(0)" onClick="doStuff()">a link that does nothing</a>
With jQuery:
<a id=mylink href="javascript:void(0)">a link that does nothing</a> $('#mylink').click(doStuff); // or $('#mylink').click(function(){ // do things });

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.