Do you guys have a hard time fighting what is wrong with the script? Actually, when the resolution is less than 992px of the browser window, the event should work. By clicking the class is added. The problem is that the event works through time. That is, for example, I do resize windows, stopped at 768, the event worked. Slightly moved the browser, everything is no longer working. A little smaller window, again earned.
https://codepen.io/brezze/pen/ERONZN
Where is the mistake ?
<div class="wrap"> <div class="item"></div> <div class="item"></div> </div> $(window).on('resize', function() { if ($(window).width() <= 992) { $('.wrap').click(function(){ $('.item', this).toggleClass('open'); }); } }).trigger('resize');
toggleClassis performed many times, respectively, the class will or will not depend on the number of handlers, namely, even their number or not even. Typeconsole.log("click")inside the click handler. - Stepan Kasyanenko