SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist
    Join Date
    Mar 2011
    Location
    Bellingham, WA
    Posts
    450
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Jquery Order of events

    Hi,

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

    Thank you,

    Eric
    Last edited by kreut; May 24, 2013 at 06:16. Reason: Clarity!

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,941
    Mentioned
    215 Post(s)
    Tagged
    12 Thread(s)
    Hi,

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

    Code JavaScript:
    $('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.

  3. #3
    SitePoint Evangelist
    Join Date
    Mar 2011
    Location
    Bellingham, WA
    Posts
    450
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    And common sense prevails!

    Enjoy your weekend...

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,840
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    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:

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

    Code:
    $('a').on("click", function(){ console.log("One"); console.log("Two"); });
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    SitePoint Evangelist
    Join Date
    Mar 2011
    Location
    Bellingham, WA
    Posts
    450
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thank you for the additional info!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •