Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#10569 closed bug (duplicate)

:focus in Chrome

Reported by: [email protected] Owned by:
Priority: low Milestone: 1.next
Component: selector Version: 1.6.4
Keywords: Cc:
Blocked by: Blocking:

Description

I have code similar to the sample bellow. I click on the text-input field. I expect the to see "is focused: true".

$('input').focus(function(){
  var isFocused = $(this).is(':focus');
  console.log( "is focused: "+isFocused );
});

It works as expected in Firefox (is focused: true) but fails in Chrome (is focused: false).

I also the tried code bellow:

$('input').focus(function(){
  var isFocused = this === this.ownerDocument.activeElement;
  console.log( "is focused: "+isFocused );
});

This time I'm getting consistent result (is focused: true).

I do understand that clicking an input field in Chrome does not effect CSS :focus state. I also understand that ":focus" and ":active" are not the same. However, I believe that the behavior of jQuery ":focus" selector is broken in Chrome.

First, I believe that jQuery ":focus" selector should be analogous to jQuery .focus() function. They should work constantly across browsers. Second, look at line 4439-4441 from jQuery source file:

focus: function( elem ) {
      return elem === elem.ownerDocument.activeElement;
    }

Related bugs: http://bugs.jquery.com/ticket/7768

Thanks,
Rafal Radulski
[email protected]

Change History (5)

comment:1 Changed 11 years ago by dmethvin

Component: unfiledselector
Milestone: None1.next
Priority: undecidedlow
Status: newopen

comment:2 Changed 11 years ago by dmethvin

I do understand that clicking an input field in Chrome does not effect CSS :focus state.

I don't understand it. Do you have a link to a reference? To me this seems like a Chrome bug. We're delegating to querySelectorAll so Chrome should be doing the right thing.

comment:3 in reply to:  2 Changed 11 years ago by Rafal Radulski <[email protected]…>

Replying to dmethvin:

I do understand that clicking an input field in Chrome does not effect CSS :focus state.

I don't understand it. Do you have a link to a reference? To me this seems like a Chrome bug. We're delegating to querySelectorAll so Chrome should be doing the right thing.

I think you are right saying it must be a Chrome bug. I read about this behavior on several forum. However, when I just tested Chrome's CSS ":focus" selector, it works correctly. Sorry for confusion.

In any case, jQuery :focus selector does not work in Chrome in the context I showed.

comment:4 Changed 11 years ago by timmywil

Resolution: duplicate
Status: openclosed

comment:5 Changed 11 years ago by timmywil

Duplicate of #10809.

Note: See TracTickets for help on using tickets.