Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Edge: .is(":focus") and .not(":focus") return wrong values #4109
code for reproducing:
When I use Edge I have strange behavior of .is(":focus") and .not(".focus")
How it should work?
What is wrong?
element is focused and selectors fetch it. But if you use .is() and .not() you will get wrong results
I reproduced it in my tests and I have to spend time to find reasons why sometimes it is working and sometimes is not working
Which browsers are affected?
my version is
other browsers are ok.
test case is attached
FWIW, that fiddle reproduces the reported behavior in Edge 42.17134.1.0 for me - when page is refreshed it logs
@fastfasterfastest I see that result as well. However, it's possible that Edge still has the async-focus behavior that the old IEs had. Focus didn't occur until the next event loop turn. If I change it to
What is the result you get and what is the result you expect?
If I change to do the logging in a
(It appears when you refresh the page, Edge does not actually cause the focus to be set to the input element at all...)
When I first used the original fiddle I got your results.
When I used the updated fiddle I got:
input focused: true input#first focused: true input:focus id: first $('input').not(':focus').length: 1 $('input:not(:focus)').length: 1 focused count: 1
Now I get the
I did too - until I realized I was using Chrome... maybe you did too? Using Edge, I get consistent results. And you must refresh the page per @komarovalexander's report to see the reported behavior.
Using the updated fiddle in Edge, I initially get (prior to the refresh):
When the page is refreshed I get:
Note, I was not the original reporter.
Nevertheless, here is a fiddle without jquery and it seems to behave "correctly" - https://jsfiddle.net/63zby1nt/9/show
Here is a fiddle w/ jquery and some
(Also strange (?) is that the focus is not actually in the input element after the refresh - the caret is not in the input element.)
That said, I opened Edge, pasted in the URL, and hit enter. This is the result I got:
input focused - $('input').is(':focus'): true input focused - qsa('input')~.any(':focus'):true input#first focused: true input:focus id: first not focus count - $('input').not(':focus').length: 1 not focus count - qsa('input')~.length:1 qsa('input:not(:focus)').length: 1 $('input:not(:focus)').length: 1 focused count - $('input:focus').length: 1 focused count - qsa('input:focus').length: 1
It seems like the issue the OP is reporting may be due to that Edge does not "fully" set focus to the input element after the page has been reloaded using the browser's "Refresh" button. When the page is reloaded using the browser's "Refresh" button it appears that the document is not given focus, as seen by probing
Nevertheless, I was curious and looked into this a little bit and noticed something interesting/weird, perhaps a bug, in jquery in this particular situation. It is not necessarily causing the issue the OP reports, but may contribute to some confusion.
I noticed that the value of
In the sample below,
This is due to that two different code paths are taken in jquery depending on whether
The result is
(*: This is strange by itself from a logic point of view -
Here is the sample that demonstrates this - I provide it, not as a fiddle to avoid any iframe issues coming into play, as code you have to save to a file and load in Edge.
I think there is an issue with jquery/Sizzle here, regardless of whether Edge "fully" sets focus after a reload or not. jquery uses two different ways to determine the value of
So to restate, hopefully little clearer...
For sample code demonstrating the issue, see preceding comment above #4109 (comment)
Condition: using Edge and page must be reloaded by using browser's "Refresh" button. Note, the page must be reloaded using browser's "Refresh" button to demonstrate the issue.
First issue is that the value of
Second issue is that if
(I don't know if this should be opened as an issue at https://github.com/jquery/sizzle/issues instead)