#13041 closed bug (wontfix)
Cannot select :focus element
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | low | Milestone: | 1.9.1 |
Component: | selector | Version: | 1.8.3 |
Keywords: | Cc: | timmywil, gibson042 | |
Blocked by: | Blocking: |
Description
Updated from 1.8.1 to 1.8.3. Noticed that :focus stopped working.
Working example: http://jsfiddle.net/AvRkY/
..or:
<ul> <li tabindex="-1">One</li> </ul> $( 'li:first-child' ).focus(); alert( $( 'ul' ).find( 'li:focus' ).size() );
Bug exists in 1.8.2 and above versions: always returns 0.
Change History (6)
comment:1 Changed 10 years ago by
Component: | unfiled → selector |
---|---|
Milestone: | None → 1.9 |
Priority: | undecided → low |
Status: | new → open |
comment:2 Changed 10 years ago by
Cc: | timywil gibson042 added |
---|
Also I should point out that the :focus
selector doesn't seem to work in Firefox on any version of jQuery so this has never been cross-browser. The Selectors Level 3 API seems to leave implementors some leeway:
The :focus pseudo-class applies while an element has the focus (accepts keyboard or mouse events, or other forms of input). ... There may be document language or implementation specific limits on which elements can become :active or acquire :focus.
http://www.w3.org/TR/selectors/#the-user-action-pseudo-classes-hover-act
timmywil or gibson042, if you don't know of a solution I'm inclined to close this wontfix.
comment:3 Changed 10 years ago by
Cc: | timmywil added; timywil removed |
---|
comment:4 Changed 10 years ago by
Milestone: | 1.9 → 1.9.1 |
---|
comment:5 Changed 10 years ago by
Resolution: | → wontfix |
---|---|
Status: | open → closed |
The spec leaves it up to the user-agent whether or not elements that are usually not focusable be focused even when the tabIndex is -1. This makes it difficult to provide any consistent behavior. This case is so edgy, I'm closing wontfix.
Here it is working in 1.8.1: http://jsfiddle.net/dmethvin/AvRkY/1/
Most likely affected by the fix for #12648.
It is not a good idea to assume an element is focused synchronously, as this does, because IE fires focus async. It seems to catch the focus immediately in its
querySelectorAll
implementation because the example above with 1.8.1 works in IE9. However, it does *not* work in IE7.It looks like you may be trying to roll your own select list, I would warn you away from doing that unless you are aware of ARIA and the issues caused with accessibility.