Reputation: 274
I've tried some similar solutions, but those were just similar.
I'd like to execute some functions on either Enter
key press or Blur
. In this case they're supposed to do the same.
$(".some_input").on("keyup blur", function(e) {
if(e.keyCode === 13) {
// some function to be executed on both of the events
}
})
So I need to add something like:
if(e.keyCode === 13 || blur) {
That's all I need and can't achieve by myself indeed.
Upvotes: 0
Views: 624
Reputation: 104775
Create your shared function
function myFunction() { }
Then create 2 different handlers, and call the function:
$(".some_input").on("blur", myFunction).on("keyup", function(e) {
if(e.keyCode === 13) {
myFunction();
}
});
Upvotes: 1