Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery onClick multiple callbacks

How do I register multiple callbacks for a jQuery event? An example of what I am trying to achieve:

$(document).on("click", ".someclass", CallbackFunction1, CallbackFunction2);

function CallbackFunction1(event) {
    //Do stuff
}

function CallbackFunction2(event) {
    //Do some other stuff
}

How can I set up the event handler to execute both callback functions when the element is clicked?

like image 759
nagyben Avatar asked Aug 05 '14 12:08

nagyben


2 Answers

You can just attach them as separate event handlers:

$(document).on("click", ".someclass", CallbackFunction1)
           .on("click", ".someclass", CallbackFunction2);
like image 54
Vatev Avatar answered Nov 07 '22 05:11

Vatev


Unless I misunderstand what you're asking, you can use a single event handler:

$(document).on('click', '.someclass', function(e){
    CallbackFunction1(e);
    CallbackFunction2(e);
});
like image 4
ajm Avatar answered Nov 07 '22 04:11

ajm