html - jquery slideUp and slidedown callback repeating -


im creating jquery accordion , triggering effect onclick, im having problem because there excess action of slideup , slidedown in last level of ul, error occurred when following actions

-

  1. click "button"
  2. -choose , click or any(a,b or c)
  3. -then select , click a.1 or any..
  4. -then click again parent a
  5. -then click open again
  6. -click of childs

as notice, click once slideup , slidedown trigger. here jquery

$(document).ready(function() { $("#ins-type").appendto("li.prd"); $("li.prd>a").click(function(event){     event.preventdefault();     $("#ins-type").slidetoggle(); }); $("#ins-type>li>a").stop().click(function(event){     event.preventdefault();     if($(this).parent().hasclass("act")){        $(this).parent().find('ul').find(".act").find('.the-ins-desc').slideup().parent().removeclass("act");         $(this).parent().find("ul.the-ins").slideup();         $(this).parent().removeclass("act");     }else{         $("#ins-type>li").removeclass("act").find("ul.the-ins").slideup();         $(this).parent().addclass("act");         $(this).parent().find("ul.the-ins").slidedown(function(){                 $(this).find('li').children('a').click(function(event){                     event.preventdefault();                     if($(this).parent().hasclass("act")){                         $(this).parent().removeclass("act");                         $(this).parent().find("ul").slideup();                         console.log("clise");                     }else{                         $(".the-ins>li").removeclass("act").find('.the-ins-desc').slideup();                         $(this).parent().addclass("act").find("ul").stop().slidedown();                         console.log("open");                     }                     return false;                 });         });     } }); }); 

fiddle sample

your last "if, else" statement, put return false in brackets.

https://jsfiddle.net/mx64mswn/1/

if($(this).parent().hasclass("act")){                         $(this).parent().removeclass("act");                         $(this).parent().find("ul").slideup();                         console.log("clise");                         return false;                     }else{                         $(".the-ins>li").removeclass("act").find('.the-ins-desc').slideup();                         $(this).parent().addclass("act").find("ul").stop().slidedown();                         console.log("open");                         return false;                     } 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -