Bug Tracker

Opened 7 years ago

Closed 6 years ago

#12111 closed bug (duplicate)

is(':visible') and filter(':visible') give different results for window and document

Reported by: homyakov@… Owned by: homyakov@…
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.

Change History (6)

comment:1 Changed 7 years ago by dmethvin

Owner: set to homyakov@…
Status: newpending

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 true under all circumstances regardless of actual visibility of the document/window, or would a consistent false be okay as well? Can you point to some code that depends on this?

comment:2 Changed 7 years ago by anonymous

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.

comment:3 Changed 7 years ago by dmethvin

Status: pendingopen

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.

comment:4 Changed 7 years ago by anonymous

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

comment:5 Changed 6 years ago by mikesherov

Component: unfiledtraversing

comment:6 Changed 6 years ago by mikesherov

Resolution: duplicate
Status: openclosed

Duplicate of #11563.

Note: See TracTickets for help on using tickets.