api.jquery.com
api.jquery.com copied to clipboard
Add reusable note to blur, focusout, focusin, focus pages
See https://github.com/jquery/jquery/issues/3123
How about something like this?
Note: Use of focus-related events are complicated by several factors. On Internet Explorer,
focusandblurare asynchronous and do not occur at the point where the.focus()method is called in your code. Thefocusoutandfocusinevents are implemented inconsistently across browsers and not implemented at all on Firefox, although jQuery simulates the event. Code should not depend on the order offocusinandfocusoutevents relative tofocusandblurbecause it varies across browsers. On all platforms,focusouton the previously focused element (if any) will always occur beforefocusinon the new one, andbluroccurs beforefocus.
blurandfocusoutwill occur on the previous element (if any) beforefocusandfocusinoccur on the newly focused element
We can only guarantee blur will happen before focus and focusout before focusin. The spec, for instance, mandates that focusin happens before blur and IE 11 follows that.
The last sentence sort of replies to what I posted above but the previous one suggests something else. I'd rephrase it.
Agreed, we can't guarantee that. Edited.
Hey @dmethvin,
In the last sentence, you can probably drop the first "relative" because it's redundant: "Code should not depend on the order of focusin and focusout events relative to focus and blur…"
Changed! There's a "fewer relatives" mother-in-law joke in here somewhere.
not implemented at all on Firefox - not in Firefox?
Also, I'd like the text to say focusout will happen before focusin and blur before focus if possible as we do guarantee that.
Agreed, updated to reflect that @mgol.
Thanks, the note looks good. I only have a grammar question: shouldn't it say in Firefox instead of on Firefox & In Internet Explorer instead of On Internet Explorer? Or have I been using English incorrectly? ;)
Sorry, i just got to this in my inbox! I think you could use on if you think of a browser as a platform or in as an environment. Either works for me. If you think you use English incorrectly, you should see me with French or Spanish.
OK, thanks for an explanation, that captures it nicely. I seem to think of a browser as an environment more than a platform so I see where my in comes from. Either works fine. :)
Note: due to https://github.com/jquery/jquery/issues/4300, jQuery 4.0 will drop the guarantee that focusin fires before focus & focusout before blur; let's make sure to not document that guarantee. :)