jQuery .closest() gets the first element that matches the selector, beginning at the current element and progressing up through the DOM tree;
<script>
$('.target').closest('.parent').css('background-color', '#ffa');
</script> |
<script>
$('.target').closest('.parent').css('background-color', '#ffa');
</script>
<div class="well">
<div class="well parent">.parent
<div class="well">
<div class="well">
<span class="target">.target</span>
</div>
</div>
</div>
</div> |
<div class="well">
<div class="well parent">.parent
<div class="well">
<div class="well">
<span class="target">.target</span>
</div>
</div>
</div>
</div>