Select lowest nested selector when clicked
- by rikAtee
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())
});