Ticket #12492 (closed bug: fixed)
In textarea focus event handler, $(this).is(':focus') == false in Chrome & Safari
| Reported by: | paulcalcraft@… | Owned by: | mikesherov |
|---|---|---|---|
| Priority: | low | Milestone: | 1.8.2 |
| Component: | selector | Version: | 1.8.0 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
jsFiddle here: http://jsfiddle.net/hJwKC/4/
All browsers report 'true,true', except Chrome and Safari which both report 'false,true'. The same is the case for <input> tags.
I'm not sure what the expected behaviour is - whether an element should only report as focused after the focus handler has completed, but the cross browser inconsistency led me to believe it could be a bug. I realise it could also be a webkit bug (or feature).
Change History
comment:1 Changed 8 months ago by dmethvin
- Status changed from new to closed
- Resolution set to wontfix
comment:2 Changed 8 months ago by mikesherov
Just to follow up even further, the API page on :focus seems to be aware of the bug and uses a setTimeout to achieve consistency: http://api.jquery.com/focus-selector/
comment:3 Changed 8 months ago by mikesherov
- Priority changed from undecided to low
- Resolution wontfix deleted
- Status changed from closed to reopened
- Component changed from unfiled to selector
- Milestone changed from None to 1.8.2
Actually, this is really easy to fix. We can just declare chrome's matchesSelector buggy for ":focus".
comment:4 Changed 8 months ago by mikesherov
- Owner set to mikesherov
- Status changed from reopened to assigned
comment:6 Changed 8 months ago by Timmy Willison
- Status changed from assigned to closed
- Resolution set to fixed
Sizzle: fix selector in Chrome 21. Fixes #12492.
Changeset: 01d406522095a26788b1975852ad7c1ee7cf6e34
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Seems like a Webkit bug to me. One workaround is to use document.activeElement, which is also a lot more efficient than using .is() with a selector. For that reason I'll close this wontfix, you could file a bug with them if you want to use the selector anyway. http://jsfiddle.net/hJwKC/7/