Given the following HTML structure:
<div class="wrap">
<div id="a"></div>
<div id="b"></div>
</div>
the following is false:
($('#a').parent() == $('#b').parent()); //=> false
even though:
$('#a').parent().children('#b').length; //=> 1
Could anyone explain why? Thanks!
I'm not 100% on exactly why it doesn't work, but I believe it is because the elements are wrapped in jQuery objects which are inherently different per element.
As a workaround, you can compare the native DOM object, like this:
($('#a').parent()[0] == $('#b').parent()[0]); // true
Example fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With