What is the variable firstClick ?
$(document).ready(function ($) { $('.icon').click(function(){ $('.header, .content').addClass('active'); if ($('.sidebar').css('left')!=$('.sidebar').width()) { $('.sidebar').addClass('active'); var firstClick = true; // Скрипт который будет закрывать sidebar при клике на любое место $(document).bind("click", function() { if (!firstClick && $(event.target).closest('.sidebar').length == 0) { // Удаляем класс active $('.sidebar').removeClass('active'); // Удаляем класс active $('.header, .content').removeClass('active'); $(document).unbind("click"); } firstClick = false; }); } e.preventDefault(); }); });
$(document).unbind("click");?! Well, you should have thought of this ... - Pavel Mayorov