I have nested elements:
<ul class="level-1">
<li class="item-i">I</li>
<li class="item-ii">II
<ul class="level-2">
<li class="item-a">A</li>
<li class="item-b">B
<ul class="level-3">
<li class="item-1">1</li>
<li class="item-2">2</li>
<li class="item-3">3</li>
</ul>
</li>
<li class="item-c">C</li>
</ul>
</li>
<li class="item-iii">III</li>
</ul>
How to get value (it’s ‘1’) from li class="item-1">1</li> when clicked? I have problem with defining right selector… How to end with something like this:
$(all children of level-1).click(function() {
alert($(this.item-1").val(););
}
Try this
$(this).text()OR$(this).html().val()is for input fields.. So you cannot access the data you seek using.val()Don’t forget
e.stoppropagation().. Otherwise you will also see the text inside the parent li..Try FIDDLE