9
I need to select the ul parent of the element li that is being clicked. But as a li is inside the other javascript understands that I am clicking on li and in all li parents.
<ul class="lista">
<li class="item">
Pai
<ul class="lista">
<li class="item">
Filho
<ul class="lista">
<li class="item">Neto 1</li>
<li class="item">Neto 2</li>
</ul>
</li>
<ul>
</li>
</ul>
I’ve tried a thousand ways to select ul, but I ended up erasing the code and I only had a small code of "debug":
$(document).ready(function () {
$(document).on('click','.item:last-child', function () {
alert($(this).parent().length);
});
});
It was only when I made this code that I was able to visualize q js understands that I clicked on the entire hierarchy of li and not only on the clicked one, even with this.
I marked it correctly by the :last-Child detail. The first answer only corrected this later. I used this in my test: http://doforneiro.com.br/lista1.html
– Joao Paulo