Reputation: 2777
Is there anyway to combine 3 conditions by "OR" in jquery? Eg, $(t_obj).keyup(function(e) || $('#sendResp').click(function(e) || $('.emo').click(function(e) {
? I have tested to combine them but I get error. How to combine them?
Upvotes: 1
Views: 283
Reputation: 10850
Where you are attempting to combine conditions, you are, in fact, interrupting 3 jQuery shorthand calls to bind()
on selectors.
If you don't interrupt the code to bind, the anonymous functions you write will be called when those events are raised.
To get the intended functionality, create your function and bind it to the events on those selectors individually as others have detailed in answers to this question.
Upvotes: 2
Reputation: 40673
Maybe this?
function doThing(){...}
$(t_obj).keyup(doThing());
$('#sendResp, .emo').click(doThing());
Upvotes: 5
Reputation: 2832
If you want them all to call the same function you can just do:
function myEventHandler(e) {
//do stuff
}
$(t_obj).keyup(myEventHandler);
$('#sendResp').click(myEventHandler);
$('.emo').click(myEventHandler);
Upvotes: 5