Bug Tracker

Modify

Ticket #12111 (closed bug: duplicate)

Opened 10 months ago

Last modified 8 months ago

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:
Blocking: Blocked by:

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

comment:1 Changed 10 months ago by dmethvin

  • Owner set to homyakov@…
  • Status changed from new to pending

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 10 months 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 10 months ago by dmethvin

  • Status changed from pending to 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.

comment:4 Changed 9 months 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 9 months ago by mikesherov

  • Component changed from unfiled to traversing

comment:6 Changed 8 months ago by mikesherov

  • Status changed from open to closed
  • Resolution set to duplicate

Duplicate of #11563.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.