Skip to main content

Bug Tracker

Side navigation

#15225 closed bug (notabug)

Opened September 01, 2014 05:42PM UTC

Closed September 01, 2014 07:18PM UTC

Last modified September 02, 2014 02:17PM UTC

isWindow doesn't recognize wrapped window elements

Reported by: AKwaschny Owned by:
Priority: low Milestone: None
Component: core Version: 1.11.1
Keywords: isWindow Cc:
Blocked by: Blocking:
Description

Calling jQuery.isWindow() on a wrapped window element, e.g. jQuery(window), returns false.

Demo: http://jsfiddle.net/zp318pk7/

Attachments (0)
Change History (5)

Changed September 01, 2014 07:18PM UTC by markelog comment:1

component: selectorcore
resolution: → notabug
status: newclosed

That's right it's not a Window object it's a jQuery object, it should return false.

Changed September 02, 2014 08:01AM UTC by AKwaschny comment:2

So why does jQuery(window).is(window) return false as well? You are basically saying once the window is wrapped, it becomes something new. That's just wrong.

Changed September 02, 2014 01:46PM UTC by gibson042 comment:3

jQuery(window).is(window) returns false because window falls through the function, node, and string checks in the code enabling .is: https://github.com/jquery/jquery/blob/10399ddcf8a239acc27bdec9231b996b178224d3/src/traversing/findFilter.js#L11-L38. This would also be true of other non-DOM objects (e.g., jQuery([ Math ]).is( Math ) === false).

jQuery collections containing non-node members (or even non-''element'' members, in many cases) don't always behave well, and .is is an area where we care about performance. But I wouldn't object to a small fix, if someone is interested in doing the legwork.

Changed September 02, 2014 02:05PM UTC by dmethvin comment:4

jQuery.isWindow seems pretty well documented to examine its object and I don't know why it would strip off wrappers or try to look into the contents of the object it's given to find a window. http://api.jquery.com/jQuery.isWindow/

For jQuery(window).is(window) the docs say window isn't a valid input, so at most that would be a feature request. It's easy to do jQuery.isWindow(jQuery(window)[0]) http://api.jquery.com/is/

Changed September 02, 2014 02:17PM UTC by AKwaschny comment:5

jQuery(document).is(document) returns true on the other hand. Well, I obviously don't get the philosophy of it. Anyway, thanks for the explanations everyone, I will just "adjust" this for my own then.