-3

How to call same javascript function for events like MOUSEOUT and when user press only ENTER key, multiple events calling same js function

1
  • onblur="javascript:search();" this is the html code i have ,need to change this for enter and onblur Commented Oct 14, 2014 at 11:22

1 Answer 1

2

You can define more than one event by separating them with a space.

$('selector').on('keyup mouseout click', function(){
   // will be called commonly
});

You can use the above with bind also. Also, you could create a separate function and pass it to each handler, but that is overkill, I suppose.

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

3 Comments

this could have been a comment as well :)
As 20k user you should've know better than to answer something like this. Close-vote as dupe instead...
@ArijitMukherjee no. It couldn't have been, since it answers the question/

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.