Reputation: 1248
Does anyone know, why jquery behaves like this:
var $test = $(window).add(document).add("body");
$test.is(window) -> false
$test.is(document) -> true
$test.is("body") -> true
How do I find out whether a jquery-object contains the window via "is"?
Upvotes: 4
Views: 58
Reputation: 452
var $test = $(window).add(document).add("body");
$test.is(function(index, elements) {
return this === window;
});
the jQuery "is()" method checks the nodeType of the elements being passed. Document has a nodeType of 9. Body has a nodeType of 1. Window has no nodeType, ergo "undefined" which evaluates to false. To get around this, build your own filtering function as illustrated above.
Upvotes: 1