Let's assume I have the following structure:
<div id="divid1">
<div id="divid2">
<div id="divid3">
</div>
<div id="divid4">
</div>
</div>
<div id="divid5">
</div>
</div>
The above code is merely an example to explain the problem so don't pay much attention to it.
Now let's assume I have the following jQuery:
$("#divid1").click(function(){});
Now.. What I want to do is the following:
- When this event is triggered (i.e. the user clicks anywhere inside the div with ID divid1) to tell me the ID of the div they are currently in. When I say the ID they are in, I mean the ID of the div they actually clicked, even though it's inside
divid1
. Let's assume they have actually clicked inside divid4. This event is triggered becausedivid4
is insidedivid2
which is insidedivid1
Constraints:
- I do not know ANY of the IDs apart from divid1. This is because I am generating the IDs of all the other divs dynamically and there is no way to know how many divs there are OR what they are called.