Lets say I have this html:
<div class="test"></div>
<div class="test"></div>
<div class="test" id="target"></div>
Somewhere in my code I call:
var $divs = $('.test');
Later, I call:
var $target =$('#target');
Now, I'd like to check if $target
is in $divs
I expected the below to log true
on the the 3rd iteration but I get false
3 times:
var $divs = $('.test');
var $target =$('#target');
console.log($target);
$divs.each(function(){
console.log($(this));
console.log($(this) == $target); // expected true on 3rd iteration
});
Looking at the console. it's obvious why this returns false.
What would be the correct way to check if $divs
contains $target
?