Side navigation
#12111 closed bug (duplicate)
Opened July 20, 2012 08:46AM UTC
Closed September 08, 2012 08:00PM UTC
is(':visible') and filter(':visible') give different results for window and document
| Reported by: | homyakov@isida.by | Owned by: | homyakov@isida.by |
|---|---|---|---|
| Priority: | undecided | Milestone: | None |
| Component: | traversing | Version: | 1.7.2 |
| Keywords: | Cc: | ||
| Blocked by: | Blocking: |
Description
When checking for visibility $(window).is(':visible') and $(document).is(':visible') return true, but $([window, document]).filter(':visible') returns empty array.
In other words, is(':visible') thinks that window and document are visible, but filter(':visible') thinks not.
Test page at http://jsfiddle.net/zHYqj/ (results for is and filter should match).
Tested in jQuery 1.6.4 and 1.7.2.
Attachments (0)
Change History (6)
Changed July 20, 2012 02:53PM UTC by comment:1
| owner: | → homyakov@isida.by |
|---|---|
| status: | new → pending |
Changed July 20, 2012 05:26PM UTC by comment:2
At least results should be consistent, but both ways have pros and cons. In common sense window and document are visible to user, so visibility checks should return true. On the other side as you said they technically are not DOM elements, so leaving them after filter() may break next code in call chain (e.g. $(window).filter(':visible').offset().left will give error).
Visual Event (https://github.com/DataTables/VisualEvent) currently depends on filter, and processes all DOM elements plus window and document and possibly document.body or document.documentElement. I've tried to replace in its code $(node).filter(':visible').length===0 with shorter !$(node).is(':visible') and found this inconsistency.
IMHO consistent false will be OK unless someone has code which already depends on this specific feature.
Changed July 24, 2012 09:41PM UTC by comment:3
| status: | pending → open |
|---|
Given the potential for breaking code that depends on one or the other, I don't think we can tackle this for 1.8. I'll mark it valid for now but it may end up being a wontfix.
Another issue I can think of here is that :visible and :hidden are generally thought of as opposites; if we say a window or document are never visible they will always be hidden.
Changed August 15, 2012 02:15PM UTC by comment:4
This bug was posted couple of months ago and closed as invalid http://bugs.jquery.com/ticket/11563
I even found it exactly the same way (while modifying VisualEvent source) :)
Changed September 05, 2012 03:24AM UTC by comment:5
| component: | unfiled → traversing |
|---|
I think this is just a case of both being inappropriate inputs, since neither of those are DOM elements and so a check for
elem.style.display == "none"doesn't make sense.Are you specifically asking for them both to return
trueunder all circumstances regardless of actual visibility of the document/window, or would a consistentfalsebe okay as well? Can you point to some code that depends on this?