Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Edit</strong></p> <p>To prevent both events from firing, you'll have to somehow mark the element before causing it to lose focus. That way, your <code>blur</code> event handler can tell if the event is the subject of a keyup, or if it legitimately lost focus. Something like this:</p> <pre><code>$(".textbox").live("blur",function (event) { if (!$(this).hasClass('keyupping')) alert("blur Event fired"); }); $(".textbox").live("keyup",function (event) { $(this).addClass('keyupping'); if(event.keyCode == 13){ // Detect Enter alert("KeyUp fired after pressing Enter"); } $(this).removeClass('keyupping'); }); </code></pre> <p>Try it out: <a href="http://jsfiddle.net/GRMule/sR6zm/" rel="noreferrer">http://jsfiddle.net/GRMule/sR6zm/</a></p> <hr> <p><strong>Original answer</strong></p> <p>When the event for <code>keyup</code> fires, it prepares to draw the browser alert dialog, which takes focus from the document and applies it to the modal dialog. This causes the blur event to fire.</p> <p>The <code>blur</code> event is then jumping in and finishing its execution context before <code>keyup</code> knows what hit it.</p> <p>This is demonstrated by using something that <em>does not</em> take the focus off the element, like <code>console.log</code>: <a href="http://jsfiddle.net/GRMule/7vRLW/" rel="noreferrer">http://jsfiddle.net/GRMule/7vRLW/</a></p> <p>The order that events fire is implementation-specific, meaning that you can't rely on Firefox acting like IE. See the spec: <a href="http://www.w3.org/TR/2000/REC-DOM-Level-2-Events-20001113/events.html#Events-eventgroupings" rel="noreferrer">http://www.w3.org/TR/2000/REC-DOM-Level-2-Events-20001113/events.html#Events-eventgroupings</a>. Try the fiddle with alerts in IE, and in this case you'll see that <code>blur</code> does hit before <code>keyup</code> in IE 7 -- and <code>blur</code> doesn't fire in Chrome!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload