Edit: Please take note that the number of parent divs may vary. It may be one or more.
I am trying everything to get the parent <div>
of a <div>
with class rat
that contains a label. So in this case, the outermost <div>
must be returned.
<div> --> Should be returned
<div>
<div class="item box1" id="box1">1</div>
<div class="item" id="box2">2</div>
<div class="item" id="box3">3</div>
<div class="item rat" id="box4">4</div>
</div>
<label>Im the original parent</label>
</div>
It can easily be done when I add class attributes for each div and use closest()
but for this case there's no unique selector that I can use.
Or we can take it this way: find the closest label of the <div>
with class rat
using the above example:
$('.rat') -> selector