Skip to main content

Bug Tracker

Side navigation

#10569 closed bug (duplicate)

Opened October 24, 2011 10:50PM UTC

Closed May 29, 2012 12:07AM UTC

Last modified May 29, 2012 12:07AM UTC

:focus in Chrome

Reported by: rrafal@gmail.com 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

rrafal@gmail.com

Attachments (0)
Change History (5)

Changed October 24, 2011 11:28PM UTC by dmethvin comment:1

component: unfiledselector
milestone: None1.next
priority: undecidedlow
status: newopen

Changed October 24, 2011 11:37PM UTC by dmethvin comment:2

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.

Changed October 25, 2011 12:46AM UTC by Rafal Radulski <rrafal@gmail.com> comment:3

Replying to [comment:2 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.

Changed May 29, 2012 12:07AM UTC by timmywil comment:4

resolution: → duplicate
status: openclosed

Changed May 29, 2012 12:07AM UTC by timmywil comment:5

Duplicate of #10809.