I’m trying to add key-controls to my rails page, so that when user press space, it would automatically click on link.
#application.js
$(document).ready(function(){
$(document).keypress(function(event) {
if (event.which === 57) {
$('#nextb').click();
}
});
});
#in index.html
<a href="#" id="nextb" onclick="some other action">
But it gives me no result at all. What am I doing wrong?
The
keyCodeof space (normalized throughwhich) should be32Demo: http://jsfiddle.net/qR2NU/5/