jquery - multiple actions need to be perform in single selector -


the case :

i've list items manipulate css selected 1 apply 'selected effect'. example once specified li clicked, run code :

    $(document).on( 'click', 'li', function (){           $('li').removeclass('selected');       $(this).addclass('selected'); }); 

but on li, needs perform other action because have link inside li:

<li class="selected"><a href="#"><span class="items">item 1</span></a><a href="#"><span class="edit">edit</span></a></li> 

this

my question :

how avoid call click function when click on other links (for example 'edit' above)? because intention not select li..

i thought of inside click function, can put 'if expression' when not edit link clicked, proceed..

but if better way..

how avoid call click function when click on other links (for example 'edit' above)?

in handler "edit" link, use event.stoppropagation() prevent bubbling li.

since you're using delegation, can this: live example | live source

$(document).on('click', '.edit', function(event) {     $("<p>do edit...</p>").appendto(document.body);     event.stoppropagation();             // <=== important bit }).on('click', 'li', function (){     $('li').removeclass('selected');     $(this).addclass('selected');     return false; }); 

(i added return false second 1 because links in lis causing page jump.)


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -