Given the html:
<div class="a">
<div class="b">
<div class="c">
<div class="d">
</div>
</div>
<div class="d">
</div>
</div>
</div>
Im interested in the selecting the parent element with class a applied to it when any element with the class ‘d’ is clicked.
I have the following javascript / jQuery, but it seems very messy. Is there a neater way?
<script>
$('.d').click(function(){
var elementA = $(this).parentsUntil('.a').last().parent();
})
</script>
You want
$(this).closest('.a').