My html is set up like so:
<div class="containerElement">
<div class="element"></div>
</div>
<div class="containerElement">
<div class="element"></div>
</div>
whenever a ".element" is clicked I want to add a class to the element's ".containerElement" and only that one instance of "containerElement".
How do I add a class to that one instance of "containerElement" in javascript whenever an element is clicked, my jquery code thus far is:
$('.element').click(function(){
$('.containerElement', this).addClass('highlighted');
})
what is the correct syntax in stead of "$('.containerElement', this)"
You can do it by referring to the direct parent of the click event target.