I have a situation in which i need a reference to the very next DIV that is the parent of my current DIV, but matches a specific class name.
<div class="container">
<div class="something">test</div>
<div class="something">test</div>
<div class="something" onclick="$(use jquery to find parent with class container)">test</div>
</div>
This would be pretty easy, but it can also look like this:
<div class="container">
<div class="someotherthing">
<div class="something">test</div>
<div class="something">test</div>
<div class="something" onclick="$(use jquery to find parent with class container)">test</div>
</div>
</div>
Which means that i am looking for a solution that recursively walks UP the dom until it finds a parent of a given element that matches a certain CSS class.
And i was wondering whether jQuery can do this in a one-shot call.
The
.closest()method should handle this: