Reputation: 46479
I have a setup like this
<ul>
<li> <a href="#">link</a>
<ul>
<li> <a href="#">link</a>
<ul> ... etc
</ul>
</li>
</ul>
So several nested uls, I need to figure out some way to find what level of nesting the ul has based on link that was clicked inside it, is it a top (1st) middle (2nd) etc.. one
Upvotes: 2
Views: 58
Reputation: 25527
You can use
$("a").click(function(){
alert($(this).parents("ul").length);
});
Upvotes: 3
Reputation: 3062
If you have clicked element <li>
(in your event handler) you can just count all parent <ul>
elements
element.parents('ul').length
Upvotes: 4