brucelee brucelee - 7 months ago 25
Javascript Question

multiple .on events AND detecting keypress

i run a function like this:

$(document).on('change, focusout', '.something', function(){ ... }


I would like the handler to also execute when keypress == 13.
What's the best approach?

Answer

Do a if statement

$(document).on('change focusout keypress', '.something', function(e){
if(e.keyCode == 13 ) {
//code here
}
 });