Reputation: 7700
I need to get the id of div where the input is contained, for example:
<div id="example">
<label for="i1">Label1</label>
<input id="i1" name="i1" type="text"/>
</div>
I hope can help me!
Upvotes: 3
Views: 106
Reputation: 100175
Do you mean:
$("div:has('input')").attr("id");
Or
$("div").has('input').attr("id");
Upvotes: 1
Reputation: 4474
$('input').on('click', function(){
alert($(this).parent().attr('id'));
});
Upvotes: 2