javascript - How to prevent assigning click event on child items? -


i made click event .menu li has ul in using $(".menu li:has(ul)"). works assigns same event .menu li ul li. tried using e.stoppropagation();, e.preventdefault(); , return false; inside function didn't worked @ all. how prevent that?

here's fiddle show actual problem.

jquery used:

$(".menu li:has(ul)").click(function() {     console.log('has ul');     if($(this).children("ul").is(':visible')){         $(this).children("ul").slideup();     }else{         $(this).children("ul").slidedown();     } }); 

try instead:

$('.menu a').click(function() {     var next=$(this).next();     if(next.prop('tagname')=='ul') {         if(next.is(':visible')){             next.slideup();         }else{            next.slidedown();         }     } }); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -