I want my jQuery plugin to behave differently, when called on a $(window) selection. How can I check, if window is in the set? My tries so far:
>>> $(window) == $(window)
false
>>> $(window).is(window)
false
>>> $(window).filter(window).length
0
(Those all work fine for document, by the way.) Of course I can always inspect this[0], but there are edge cases like $('a').add(window) that are not catered by this approach.
I can also filter via function:
>>> $(window).filter(function() { return this === window; }).length
1
but I was hoping for a bit more ‘jQuery-ish’ or generic approach.
You can use index() and pass it the
windowobject. It will return-1if thewindowobject is not part of the set, or its zero-based index within the set otherwise: