Opened 6 years ago
Closed 6 years ago
#12492 closed bug (fixed)
In textarea focus event handler, $(this).is(':focus') == false in Chrome & Safari
| Reported by: | Owned by: | mikesherov | |
|---|---|---|---|
| Priority: | low | Milestone: | 1.8.2 |
| Component: | selector | Version: | 1.8.0 |
| Keywords: | Cc: | ||
| Blocked by: | Blocking: |
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 (6)
comment:1 Changed 6 years ago by
| Resolution: | → wontfix |
|---|---|
| Status: | new → closed |
comment:2 Changed 6 years ago by
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 6 years ago by
| Component: | unfiled → selector |
|---|---|
| Milestone: | None → 1.8.2 |
| Priority: | undecided → low |
| Resolution: | wontfix |
| Status: | closed → reopened |
Actually, this is really easy to fix. We can just declare chrome's matchesSelector buggy for ":focus".
comment:4 Changed 6 years ago by
| Owner: | set to mikesherov |
|---|---|
| Status: | reopened → assigned |
comment:6 Changed 6 years ago by
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
Sizzle: fix selector in Chrome 21. Fixes #12492.
Changeset: 01d406522095a26788b1975852ad7c1ee7cf6e34

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/