Currently, I am working on designing dynatree and the nodes are structured within ul and li tags. However, I am encountering an issue where I am unable to retrieve the parents of the clicked li element.
Below is a snippet of my HTML code:
<ul class="bulk">
<li>gp1
<ul>
<li>gp2
<ul>
<li>gp3
<ul>
<li>c1
<li>c2
<li>c3
</ul>
<li>gp4
</ul>
</li>gp5
<ul>
<li>gp6
<ul>
<li>gp7
<ul>
<li>c4
<ul>
<li>c5
<li>c6
</ul>
</ul>
</li>gp8
<li>gp9
</ul>
<li>gp10
</ul>
</ul>
</ul>
Here is a jQuery method I have implemented:
$('ul.bulk li').click(function(e)
{
alert(e.html());
});
You can view the implementation in action on this fiddle: http://jsfiddle.net/raghavendram040/ojnLrcjz/
The issue I am facing is that when I click on 'gp3', it alerts me 3 times instead of its parent elements like gp1 and gp2. All the li and ul elements are placed dynamically except for the tag. Any help or guidance on how to solve this problem would be greatly appreciated.