Bug Tracker

Opened 8 years ago

Closed 7 years ago

Last modified 7 years ago

#11563 closed bug (invalid)

Inconsistent behavior of :visible pseudo-selector for document

Reported by: anonymous Owned by: anonymous
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.2
Keywords: Cc:
Blocked by: Blocking:

Description

console.log($(document).filter(':visible').length); 0 console.log($(document).is(':visible')); true console.log(document.nodeType); 9

This bug is coused by nodeType checking in winnow function (document has nodeType = 9). ​

Change History (11)

comment:1 Changed 8 years ago by anonymous

Sorry for typo and broken formatting.

comment:2 Changed 8 years ago by sindresorhus

What is the usecase? The document is always visible.

comment:3 Changed 8 years ago by sindresorhus

Owner: set to anonymous
Status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket.

Additionally, be sure to test against the jQuery Edge version to ensure the issue still exists. To get you started, use this boilerplate: http://jsfiddle.net/FrKyN/ Open the link and click to "Fork" (in the top menu) to get started.

comment:4 Changed 8 years ago by dmethvin

Agreed on the question about use case. If you're trying to determine whether the page is visible on the screen you might use the Page Visibility API.

comment:5 Changed 8 years ago by anonymous

Status: pendingnew

This bug was noticed in code, that processed all events on the page in the following way:

  • get a list of all events grouped by element
  • if element is not visible (filter(':visible').length === 0) then skip it
  • otherwise do something with events

That silently skipped all live events on the page.

So I wouldn't think too much of the use case - you just never know when somebody writes similar code that looks completely correct but causes unexpected behavior.

comment:6 Changed 8 years ago by dmethvin

get a list of all events grouped by element

Which documented method gives you that list?

This isn't much different than other invalid uses of an API call or selector, for example $(document).append("hello") or $(window).find("body") don't work either.

Since the document isn't an element, you need to remove it from the collection. Same goes for the window object or plain objects, which are sometimes wrapped in a jQuery collection.

comment:7 Changed 8 years ago by dmethvin

Status: newpending

comment:8 in reply to:  6 Changed 8 years ago by anonymous

Status: pendingnew

Replying to dmethvin:

get a list of all events grouped by element

Which documented method gives you that list?

That is custom code (reading jQuery.cache). It is used to visualize all events on the page.

Really have nothing more to say, just small inconsistency that was found in real code (not production though).

comment:9 Changed 8 years ago by Rick Waldron

jQuery.cache is not a documented public API and user code should never access it.

comment:10 Changed 7 years ago by dmethvin

Resolution: invalid
Status: newclosed

comment:11 Changed 7 years ago by mikesherov

#12111 is a duplicate of this ticket.

Note: See TracTickets for help on using tickets.