Reputation: 1576
I've this code :
$(a).parent().parent().parent().addClass('ITWORKS');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<p>
<span>
<a href="#">
Hello world
</a>
</span>
</p>
</div>
Instead of writing this long line of code, How can I target the div
only with the link
Thanks for your help !
Upvotes: 1
Views: 15
Reputation: 39004
Simply use .closest('div.conatiner')
See the docs of .closest() here.
Upvotes: 2