I have this code:
<div class="container">
<div class="row">
<div class="col">
<a href="1" class="delete_activity">x</a>
</div>
</div>
<div class="row">
<div class="col">
<a href="2" class="delete_activity">x</a>
</div>
</div>
<div class="row">
<div class="col">
<a href="3" class="delete_activity">x</a>
</div>
</div>
</div>
After the click on “delete_activity” I need to remove the “row” div that have that link.
In the case the user click on X (href=1) i need to remove:
<div class="row">
<div class="col">
<a href="1" class="delete_activity">x</a>
</div>
</div>
How can I do it with JQuery?
The best way to do this is use
closest().Don’t use
parents(unless thats the behaviour you want).closestwill only remove the first element found up the DOM tree.parentswill remove ALL elements matched up the DOM tree.