Need help finding the ID of the outermost parent div
<div class="panel" id="Kudapanel"> //Top-level Div
<div class="Kudapanel1" id="Kudapanel1">
</div>
<div>
<div>
<input type="button" id="yo"> //Deeply nested element
</div>
</div>
</div>
Consider the following scenarios:
- If the top-level div has a specific classname, how can you retrieve the ID of that div?
- If the top-level div doesn't have the specified classname, how can you find the ID of its immediate parent div?
I attempted the following:
$("#yo").click(function(){
alert($(this).closest('div').attr('id'));
});
Please avoid using parent().parent().parent(), as the position of the outermost div may vary in different contexts.