1

Since i'm pretty new to js and jquery i was wondering if it's possible to bind more than one key to an event. I tried ||, ,and or without any luck.

I'd like to bind a and left-arrow in an single case instead of making another case.

$(document).keydown(function(event) {
    switch(event.keyCode){
        case (37 or 65):
            alert("left");
            break;
    }
});
Sven Rojek
  • 5,476
  • 2
  • 35
  • 57

2 Answers2

1
$(document).keydown(function(event) {
    switch(event.keyCode){
        case 37:        
        case 65:
            alert("left");
            break;
    }
});

Fiddler: http://jsfiddle.net/Rn8kY/

Stefan
  • 14,826
  • 17
  • 80
  • 143
0

Simply list the cases you need grouped one below the other without a break in between.

switch(event.keyCode){
    case 37:
    case 65:
        alert("left");
        break;
}
techfoobar
  • 65,616
  • 14
  • 114
  • 135