Jquery Order of events

Hi,

If two click events are associated with one link, how exactly is the order determined?

Thank you,

Eric

Hi,

jQuery event handlers execute in the order they were bound.
For example:

$('a').on("click", function(){ console.log("One"); });
$('a').on("click", function(){ console.log("Two"); });

will cause “One”, followed by “Two” to be logged to the console, when the link is clicked.

And common sense prevails! :slight_smile:

Enjoy your weekend…

You shouldn’t be attaching the processing that way if the order matters. That way of coding is for when the order doesn’t matter - while current browsers all run them in the same order there is nothing requiring them to do so.

If the order matters then don’t use:

$('a').on("click", function(){ console.log("One"); });
$('a').on("click", function(){ console.log("Two"); });

use

$('a').on("click", function(){ console.log("One"); console.log("Two"); });

Thank you for the additional info!