/* @author Bryan Gullan @description Bind mouse click and enter key to a given element. On Click or Enter, specified function is called and default event action blocked. Sample use is to add popup to a link, where the href would be followed if javascript were turned off. var popup = function() { alert('activated'); }; $(document).ready(function() { $.clickOrEnter('a',popup); }); (c) 2007 Bryan Gullan. Use and distribute freely with this header intact */ jQuery.clickOrEnter = function(element,callback) { jQuery('a').bind('click', function(event) { callback(); event.preventDefault(); //prevent browser from following the actual href }); jQuery('a').bind('keypress', function(event) { var code=event.charCode || event.keyCode; if(code && code == 13) {// if enter is pressed callback(); event.preventDefault(); //prevent browser from following the actual href }; }); };