I have this HTML structure :
<ul>
<li class="foo">
content1
<ul>
<li class="foo">
content2
<ul>
<li class="foo">
content3
<!-- N levels of depth -->
</li>
</ul>
</li>
</ul>
</li>
</ul>
I would like to retrieve the second <li>
element (containing "content2") on a click event. I'm currently using this method :
$('body').on('click', '.foo', function() {
var $this = $(this);
// Do something with the element
});
However, as you can guess, this will also select the parent element as it also contains a foo
class. I would like select the most "accurate" node without triggering the event for the parent element (eg: if I click on content3, it should only trigger the event for this element, not his parents).
Any suggestion ?