Skip to main content

Bug Tracker

Side navigation

#11563 closed bug (invalid)

Opened April 06, 2012 11:18AM UTC

Closed May 05, 2012 05:12PM UTC

Last modified September 08, 2012 08:00PM UTC

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).

Attachments (0)
Change History (11)

Changed April 06, 2012 11:20AM UTC by anonymous comment:1

Sorry for typo and broken formatting.

Changed April 06, 2012 12:48PM UTC by sindresorhus comment:2

What is the usecase? The document is always visible.

Changed April 06, 2012 12:49PM UTC by sindresorhus comment:3

owner: → 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.

Changed April 06, 2012 12:52PM UTC by dmethvin comment:4

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.

Changed April 08, 2012 12:04PM UTC by anonymous comment:5

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.

Changed April 08, 2012 01:22PM UTC by dmethvin comment:6

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.

Changed April 08, 2012 01:23PM UTC by dmethvin comment:7

status: newpending

Changed April 08, 2012 07:19PM UTC by anonymous comment:8

status: pendingnew

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

Changed April 08, 2012 08:17PM UTC by rwaldron comment:9

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

Changed May 05, 2012 05:12PM UTC by dmethvin comment:10

resolution: → invalid
status: newclosed

Changed September 08, 2012 08:00PM UTC by mikesherov comment:11

#12111 is a duplicate of this ticket.