Skip to main content

Bug Tracker

Side navigation

#14709 closed bug (notabug)

Opened January 20, 2014 05:53PM UTC

Closed January 23, 2014 04:11AM UTC

$(window).is(":visible") incorrectly returns false

Reported by: Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.10.2
Keywords: Cc:
Blocked by: Blocking:

From jQuery 1.10 onwards, the is() method returns false instead of the expected true when applied to the window object and the :visible selector. This occurs on all the browsers I could test under (Internet Explorer, Firefox, Chrome).

Test case:

Steps to reproduce: Print the value returned by $(window).is(":visible").

Expected behavior: is() should return true.

Observed behavior: is() returns false.

Reproduced on:

  • 1.10.2
  • 1.11.0pre (a3cd88f14bc99cbb80e6abe939576cbed093cb47)
  • 2.0.2
  • 2.1.0pre (38c122a73a843a0d117d4f962cc94fda6f553086)

Last known version with correct behavior:

  • 1.9.1
Attachments (0)
Change History (5)

Changed January 20, 2014 08:22PM UTC by dmethvin comment:1

owner: →
status: newpending

Not sure this is a valid use of .is(), since a window is not a DOM element. What is your use case that leads you to call code like that?

Changed January 20, 2014 08:53PM UTC by comment:2

status: pendingnew

I'm currently using the jquery.nicescroll plugin in our project. It can augment both the page itself and arbitrary containers, and maintains references to these elements -- or, in the page's case, to window instead of say, the <body> element. This leads to code in the plugin like:

self.jqbind(self.rail, "mouseenter", function() {
    if (!":visible"))
        return false;
    // Show scrollbar widget...

Where is a jQuery object that can either contain a DOM element or window. The visibility check fails for window in jQuery 1.10+, so the plugin fails to show its scrollbar widget on mouseenter for the main page only.

I can fix the plugin, and probably also special-case is() for window, but IMHO that would not beat the original (pre-1.10) behavior being restored. I suspect it might not be as easy as I think, though.

Changed January 20, 2014 09:20PM UTC by dmethvin comment:3

I think the original behavior on window has always been undefined, the docs say this:

:visible Selects all elements that are visible in the document. ... Elements are considered visible if they consume space in the document.

Since window is not an element and is also not "in the document" I don't think it fits the description of valid inputs. It's similar to saying $({visible:1}).is(":visible"), we just don't guarantee what that will return. There are a lot of things you can do to elements that you can't do to a window.

I'd recommend changing the plugin logic. Is jquery.nicescroll abandoned? I've been trying to get some response to issues and even volunteered to help, but nothing seems to be going on with it. It's got a bunch of fragile browser sniffs that are causing problems in several environments including IE10/11 and Chrome >31. So jQuery's changed behavior on an invalid input is probably the least of our worries.

Changed January 20, 2014 09:40PM UTC by anonymous comment:4

You have a point, nothing was actually specified for window in the first place. This probably is enough of an edge case that I can live with it.

Maybe the documentation for is() could be updated to say its behavior is undefined for window (and probably also document)?

I'll try a pull request to the plugin once I get this fixed on my side, two months of inactivity are not that much after all.

Changed January 23, 2014 04:11AM UTC by dmethvin comment:5

resolution: → notabug
status: newclosed