jQuery href

04.Aug.2010

When you want to put a link onto a webpage and you want to run a jQuery function on that link, you probably want to attach listener to onclick event. To do that, simply copy following snippet:

1
2
3
4
5
6
7
<a href="javascript:void(0);" id="my-jquery-href">Don't click jQuery href</a>
 
<script>
	jQuery('#my-jquery-href').click(function() {
		alert("I said don't click jQuery href. Damn.");
	});
</script>