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
Post a Comment