I’m developing a html with this structure
div id="menuContainer">
<div class = "menu ui-accordion-header ui-state-default ui-corner-all">
<label class="formatText">Cliente</label><span class="ui-icon ui-icon-triangle-1-e menuIcon" style="float: right"></span>
<div class = "subMenu ui-accordion-header ui-state-default ui-corner-all">
<ul class="options">
<li>
<label class="formatText">Ver Cliente</label><span class="ui-icon ui-icon-triangle-1-e" style="float: right"></span>
<div class = "subMenuRight ui-accordion-header ui-state-default ui-corner-all">
<ul class="options">
<li>
<label class="formatText">Por Nombre</label><span class="ui-icon ui-icon-triangle-1-e" style="float: right"></span>
<div class = "subMenuRight ui-accordion-header ui-state-default ui-corner-all">
<ul class="options">
<li><label class="formatText">sub sub menu</label></li>
<li><label class="formatText">prueba</label></li>
</ul>
</div>
</li>
<li>
<label class="formatText">Por Campana</label>
</li>
</ul>
</div>
</li>
<li>
<label class="formatText">Reportes para Cliente</label>
</li>
</ul>
</div>
</div>
</div>
notice that the principal div have class called menu, in the inside there are a some divs that with a classes called subMenu and subMenuRight, my problem it’s that i want associate a event click to the father and other behavior to the divs children i tried like this
$(".menu").click(function () {
alert('click in the father');
});
$(".subMenu li").click(function () {
alert('click in the first child');
});
$(".subMenuRight li").click(function () {
alert('click in the second child');
});
The problem with this code it’s that div father contains the divs children all the event handler are triggered. So my question is How can I modify the selector or validate the in the event handler for to only fire the exactly element that is clicked??
use
event.stopPropagation()for all the click handlers e.g.here is the fiddle http://jsfiddle.net/yFFGS/