Jquery click link not working
I have the following code:
<script type="text/javascript"> $(document).ready(function(){ shortcut.add("Ctrl+Alt+N", function() { $("#btnSave").click(); }); }); </script> where btnSave is a binding element with identifier btnSave, shortcut from http://www.openjs.com/scripts/events/keyboard_shortcuts/ . If I change the line $("#btnSave").click(); on document.getElementById("btnSave").click() - everything works fine. The question is why the jquery implementation does not work in my case?
PS: did jsfiddle for my case: http://jsfiddle.net/0x49D1/WCmeU/
Here is a guy with a similar problem: http://forums.asp.net/t/1591818.aspx
Instead of $("#btnSave").click(); try $("#btnSave").trigger('click');
You can also use $("#btnSave")[0].click(); which jquery is equivalent to document.getElementById("btnSave").click();
Update :
It is not possible to simulate a link to a user link from javascript, for security reasons all you can do is bind your own handler for the click event and redirect the links based on href , for example:
$("#btnSave").bind('click', function() { window.location.href = $(this).attr('href'); }); try it
<script type="text/javascript"> $(document).ready(function(){ shortcut.add("Ctrl+Alt+N", function() { $("#btnSave").live('click',function(){ // do stuff here }); }); }); </script>