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;
    }
});
0

2 Answers 2

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

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

Sign up to request clarification or add additional context in comments.

Comments

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;
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.