Select lowest nested selector when clicked
Posted
by
rikAtee
on Stack Overflow
See other posts from Stack Overflow
or by rikAtee
Published on 2012-10-15T22:54:17Z
Indexed on
2012/10/15
23:01 UTC
Read the original article
Hit count: 147
I would like to click $('.sub-menu')
selector and return the lowerst nested item that was clicked, rather than the highest. e.g., when I click "enlish", "root" is returned becasue "english" is a child of "root". I want "english" returned when I select "english".
<div ID="browse_container">
<div class="sub-menu">Root
<div class="sub-menu">English</div>
<div class="sub-menu">Maths
<div class="sub-menu">Year 1</div>
<div class="sub-menu">Year 2</div>
</div>
<div class="sub-menu">? Science</div>
</div>
</div>
my script is simply:
$('.sub-menu, #root').on('click', function(event){
alert($(this).text())
});
© Stack Overflow or respective owner