Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: contains() always returning true

I have a parent jQuery object and a child jQuery element.
I'd like to see if the child is already contained within the parent. I was thinking of using jQuery's contains() method. However, in Chrome and IE I always get true returned and in FF6 I get an error a.compareDocumentPosition is not a function

Am I using this incorrectly? Is there a better way to achieve this?

Fiddle

Code:

<div class="metroContainer">
<div class="metroBigContainer">
    <div id="big1" class="metroBig">
        Stuffs 1
    </div>

    <div id="big2" class="metroBig">
        Stuffs 2
    </div>
</div>

<div class="otherContainer">
</div>

// I expect false, returns true
$.contains($('.metroBigContainer'), $('.otherContainer'))
like image 375
Mike Fielden Avatar asked Dec 28 '22 13:12

Mike Fielden


1 Answers

I believe contains takes dom elements, not jquery objects:

$.contains($('.metroBigContainer')[0], $('.otherContainer')[0])
like image 138
James Montagne Avatar answered Dec 30 '22 03:12

James Montagne