I have a DIV which I want to be removed when I click a link contained inside that DIV. Here is what I have:
<div id="clients-edit-wrapper">
<div class="close-wrapper">
<a href="#" class="close-div">Close</a>
</div>
</div>
When I click “Close” I want clients-edit-wrapper to be removed. I’m looking for a way to do this by referencing the parent DIV of the Close link which, in this case, is clients-edit-wrapper.
Any help would be greatly appreciated!
Answer from Huangism below:
$('.close-div').click(function(){
$(this).parent().parent().remove();
});
This only works if the element you would like to remove is two parents up. In my case, this is exactly what I needed.
given your html markup
Updated to .on()
More flexibility with
.closest, this gives you the option to have more more parents or less parents.https://api.jquery.com/closest/
Edit
(Added related resources)
Please see jQuery documentation on live()
As far as I know this is due to memory concerns/issues with
live().