Binding Keyboard To Onclick Event
I am having problems with a jquery slideshow where I want to bind next/right to make the images jump forwards/back. I used the following code to attempt to do it but it simply refr
Solution 1:
This should work:
$(function() {
$(document).keyup(function(e) {
switch (e.keyCode) {
case37:
$('#prev a')[0].onclick();
break;
case39:
$('#next a')[0].onclick();
break;
}
});
});
Just call the onclick
event handler of the left or right button based on which key you pressed.
Solution 2:
$(function() {
$(document).keyup(function(e) {
switch (e.keyCode) {
case37:
$('#prev').click();
break;
case39:
$('#next').click();
break;
}
});
});
Post a Comment for "Binding Keyboard To Onclick Event"