#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 11 years ago by
comment:3 Changed 11 years ago by
Owner: | set to anonymous |
---|---|
Status: | new → pending |
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 11 years ago by
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 11 years ago by
Status: | pending → new |
---|
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 follow-up: 8 Changed 11 years ago by
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 11 years ago by
Status: | new → pending |
---|
comment:8 Changed 11 years ago by
Status: | pending → new |
---|
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 11 years ago by
jQuery.cache is not a documented public API and user code should never access it.
comment:10 Changed 11 years ago by
Resolution: | → invalid |
---|---|
Status: | new → closed |
Sorry for typo and broken formatting.