Please tell me why debounce does not work.

function debounce(func){ var timer; return function(event){ if(timer) clearTimeout(timer); timer = setTimeout(func,300,event); }; } $(window).on("resize",debounce(function(e){ if ($('body, html').width() < 768) { $('.credit-type-list__title').on("click", function() { console.log("click"); $(this).nextAll('ul').children('.item').slideToggle(); $(this).children('img').toggleClass("active"); }); } })); 

  • one
    Why do you think that works wrong? - Stepan Kasyanenko
  • .toggleClass works several times - Vlad Rublenko
  • Well, that's fine. Do you know why debounce used? - Stepan Kasyanenko
  • If I understand everything correctly (then in my own words) the function call does not happen all the time, but only during the next call and what a time interval it is. Something like this I understand from what I read on the Internet. Well, they use it so as not to load the site, so that there is no constant function call - Vlad Rublenko
  • Tell me how you can realize when resize only one call - Vlad Rublenko

0