Reputation: 29514
I am having a Html like ..
<div id="Field1">
<label id="label1">Name</label><br/>
<input type="text" data-attr="text" style="width: 200px;" id="input1"/>
<br/>
<label id="instr1"/>
<div class="xfb-row-options1>
<a class=button-delete src=">-
<a title="Add" class="button-add"> +</a>
</div>
</div>
on clicking on the button delete1 i want to delete the full Div Field1. I want to get to the know the Id of the Parent's parent of button-delete1 that is Field1 . how to get so??
i.e on click of button-delete
$(".button-delete1").click(function(){
// (*)
});
(*) Here I want to find the id of Field1 that is the parent holding the class button- delete so that I can use its id value that is Field1 mainly that 1 and i can delete that DIV fully.
Please suggest me.
Upvotes: 1
Views: 104
Reputation: 72504
Use the parent()
method:
(".button-delete1").click(function() {
alert($(this).parent().parent().attr("id"));
});
Upvotes: 2