I have this sequence of divs
<div class="abuelo1">
<div class="padre">
<div class="nieto1">
<div class="nieto2">
</div>
</div>
The thing is that by means of a grandchild2 I want to eliminate grandpa1 with its content, while through grandchild1 I want to add a grandpa2 under grandpa1 with all the structure he has (Note: there is only one grandchild1 and grandchild2 for each grandparent , I do not want to add more). Any idea how to do it? I know that with
$(".nieto2").click(function () {
$('this').parent().remove();
});
eliminate only the "father" div, but I also want to eliminate the grandfather.
As they are going to be added and deleted dynamically, I want to eliminate and add grandparents from their own grandchild, not in general.