javascript - Click handler inside another -


i have structure uses couple of list elements hold anchor tags. basically, have click handler on list element itself, , click handler on anchor tag within it. however, issue having when click on anchor tag, fires list element's click handler.

$(".mystructure").on("click", ".mylis", dosomeaction);  $(".mystructure").on("click", "#mylink2", dosomeaction2);
<div class="mystructure">    <li class="mylis">      <a id="mylink">abc</a>    </li>    <li class="mylis">      <a id="mylink2">abc</a>    </li>  </div>

can tell me can when click on anchor tag invokes method want to? can't seem find out can do.

you can call event.stoppropagation() link event handler.

event.stoppropagation()

prevents event bubbling dom tree, preventing parent handlers being notified of event.

function dosomeaction2(event) {     //your code     event.stoppropagation(); } 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -