jQuery href

In: JavaScript

August 04th, 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>

Written by

Dejan is pragmatic software developer with Master's Degree in Computer Science. He is currently based in Belgrade (Serbia).