Skip to main content

Bug Tracker

Side navigation

#14598 closed bug (duplicate)

Opened December 03, 2013 03:18AM UTC

Closed December 08, 2013 03:22PM UTC

Testing :focus on multiple elements with is(), has(), filter(), ...

Reported by: mett.work@gmail.com Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.10.2
Keywords: Cc:
Blocked by: Blocking:
Description

Demo: I select multiple elements with .text-block selector.

I want to check if ANY element has the focus (one of them has when executing this code), here are the results :

$('.text-block').is(":focus") // returns false
$('.text-block').has(":focus") // returns empty object array
$('.text-block').filter(":focus") // returns empty object array on FF,returns the focused element on chrome
$('.text-block:focus') // returns the focused element

You can see that only $('.text-block:focus') works for both FF and chrome.

The problem is that when you have the elements as a variable, $textBlocks, you can't use the version that works anymore.

Attachments (0)
Change History (3)

Changed December 03, 2013 04:46PM UTC by mett.work@gmail.com comment:1

Here is the jsfiddle test case:

http://jsfiddle.net/kMD6U/

Try to focus on one of the divs, and you'll notice that on FF and Chrome, the result is different for filter() for example.

Changed December 03, 2013 04:48PM UTC by anonymous comment:2

and forgot to mention that result for .is(":focus") is also different in the two browsers

Changed December 08, 2013 03:22PM UTC by dmethvin comment:3

resolution: → duplicate
status: newclosed

Duplicate of #13041.Some of this is misunderstanding of the APIs, and the rest is a Firefox inconsistency (not sure if it can be called a bug).

$('.text-block').is(":focus") // returns false

That will only check the first element, per .is().

$('.text-block').has(":focus") // returns empty object array

That is incorrect use of .has(), which checks whether any descendant elements match the selector.

$('.text-block').filter(":focus") // returns empty object array on FF,returns the focused element on chrome

That is duplicate of #13041.