jQuery - Prevent default hyperlink behaviour when the click event calls user defined function

by sunil ravulapalli /30. January 2009 17:19 /jquery /Comments (0)

This may be obvious to many, but I am stupid, so it took me a while to figure this out.

When we bind a click behavior like this:
$("#temp").click( function(){ onClick("hello"); } );
and you want to prevent default behaviour of the click using preventDefault() you have to do:
$("#temp").click( function(e){ onClick("hello"); e.preventDefault(); } );

blog comments powered by Disqus