I’ve got:
$(‘#accordion > li).click(function () {
But it run’s if the #accordion li ol li is clicked as well.
Here’s the html markup:
<ul id="accordion">
<li id="test1">
<a href="#">Test</a>
<ol>
<li>
<a href="#">test</a>
</li>
</ol>
</li>
</ul>
The problem is that the events on the descendant elements bubble up to the ancestor element. Stop this by checking whether the originating element’s (
event.target) first ancestorliis the one where the function is being handled:See
event.targetclosestis