Bug Tracker

Opened 6 years ago

Closed 6 years ago

Last modified 3 years ago

#7340 closed bug (fixed)

.focus() not triggering focusin event for .live binding (1.4.3)?

Reported by: AP Erebus Owned by: dmethvin
Priority: blocker Milestone: 1.5.2
Component: event Version: 1.4.3
Keywords: regression Cc:
Blocked by: #8036 Blocking: #8275


As demonstrated with this jsFiddle (http://jsfiddle.net/yt7Jd/2/), the focusin even isn't being triggered when .focus() is called.

This appears to be a bug introduced in 1.4.3 as when you change the jQuery version 1.4.2, it works correctly (as seen in this jsFiddle http://jsfiddle.net/yt7Jd/1/

I am testing on Chrome Stable 7.0.517.41

Change History (19)

comment:1 Changed 6 years ago by rwaldron

  • Component changed from unfiled to event
  • Keywords regression added
  • Milestone changed from 1.5 to 1.4.5
  • Priority changed from undecided to blocker
  • Status changed from new to open

comment:2 Changed 6 years ago by dmethvin

  • Owner set to dmethvin
  • Status changed from open to assigned

comment:3 Changed 6 years ago by dmethvin

It's this commit: https://github.com/dmethvin/jquery/commit/88068f82c199847d3679b130664dd91cc2e89f00

A focus from user action or DOM .focus() works fine, but a $().focus() is ignored. The test case seems to have intentionally used a DOM focus.

comment:4 Changed 6 years ago by dmethvin

  • Milestone changed from 1.4.5 to 1.5

comment:5 Changed 6 years ago by dmethvin

#8004 is a duplicate of this ticket.

comment:6 Changed 6 years ago by leeoniya@…

RE: https://forum.jquery.com/topic/v1-4-3-unexpected-focus-behavior

even in 1.4.2, sequentially calling focus() on a,b,c is not exactly what the browsers do.


  1. focus a
  2. focusin a
  3. focus b
  4. focusout a
  5. focusin b
  6. focus c
  7. focusout b
  8. focusin c

native (no jquery):

  1. focus a
  2. blur a
  3. focus b
  4. blur b
  5. focus c

this is reproducible both manually (mouse/keyboard) and in code

i believe a proper mix should therefore be


  1. blur document.activeElement
  2. focusout document.activeElement (bubbles)
  3. change document.activeElement (if there was a change)
  4. haschanged document.activeElement (maybe a new bubbling change event)
  5. focus a
  6. focusin a (bubbles)


repeat above


repeat above

this is all logged using $('input').bind('focus blur focusin focusout'), not live() or delegate.

blur() should also work via 1-4. i know that different browsers fire change events before or after blur events, so the change() order might be screwy, but a custom "haschanged" or "changed" should always fire reliably after focusout().

just random thoughts of course,


comment:8 Changed 6 years ago by leeoniya@…

i'm not too familiar with the details of the event dispatcher in jquery. i only know the high level overview of what's done (uniformize events via fix(), live handlers for blur/focus/change done via capture, then focusin/out triggered on e.target)

i'll try to slap a patch together that fires off events in the way i've outlined. also noticed there's a .specialChange there already, will need to dig further. preferably, i'd like to get something consistent into 1.5 final since changes to event dispatch order can be chalked up to a major version bump.

are there any IRC logs relating to discussions of event flow that i can read through instead of trying to make sense of everything through code analysis?

thanks, leon

comment:9 Changed 6 years ago by dmethvin

  • Blocked by 8036 added

comment:10 Changed 6 years ago by john

  • Milestone changed from 1.5 to 1.6

Pushing to 1.6.

comment:11 Changed 6 years ago by leeoniya@…

might as well add this in here, hacked together some jquery-less event delegation code that has consistent event order (no IE)


yes, there are numerous issues, just proto. technically if you want to catch focusin/out without delegating a blur/focus at same time...those first-order handlers should be registered capturing on document implicitly during lib init. (i think jq does this already)


comment:12 Changed 6 years ago by jitter

  • Blocking 8275 added

(In #8275) Thanks for taking the time to contribute to the jQuery project by writing a bug report and providing a test case!

jQuery 1.4.4 contained some code to make focusin/focusout bubble also in non IE-browsers. But the code was buggy and got removed for 1.5 .

You can follow the ticket #7340 for progress on this issue.

In the meantime you should be able to workaround this problem by binding to the focus event instead of focusin.

comment:13 Changed 6 years ago by dmethvin

  • Milestone changed from 1.6 to 1.5.2

comment:15 Changed 6 years ago by john

  • Resolution set to fixed
  • Status changed from assigned to closed


comment:16 Changed 6 years ago by dmethvin

#8582 is a duplicate of this ticket.

comment:17 Changed 6 years ago by harriswong


I have some issues with trigger('focus') firing twice as of 1.5.2, 1.6beta, and the git version. Here is an example: http://jsfiddle.net/WVcy5/

In this example, I binded 'focus' and 'focusin' to an object and simply trigger('focus') on it.

expected output:

Focus called, count is :1 Do nothing

actual output:

Focus called, count is :1 Do nothing Focus called, count is :2

It seems like trigger('focus') would cause "focus" to fire twice if "focusin" is also binded, is this expected behavior?

Thanks, Harris

comment:18 Changed 6 years ago by harriswong

In addition to my previous post, it seems like it's only a problem when "tabindex" is in the element. I tried it on 1.6rc1 and the problem remains.

To demonstrate, you can checkout my github unit test here: https://github.com/harriswong/infusion/blob/FLUID-4113-test/src/webapp/tests/component-tests/reorderer/html/jQueryEventFocus-test.html

Or you can try this example here: https://github.com/harriswong/infusion/blob/FLUID-4113-test/src/webapp/tests/component-tests/reorderer/js/harris2.html

Thanks, Harris

comment:19 Changed 3 years ago by anonymous

Interesting to see ... thank you it's well done :)fuktskada

Note: See TracTickets for help on using tickets.