I have jQuery code that opens and closes a block when I click on a header. The problem is that if you click on it many times, then the block continues to open and close until it does this as many times as you clicked, how to fix it? Here is the jQuery code:
$(document).ready(function(){ var flag = 0; $("#top_name").click(function(){ if(flag == 0){ $("#auth_form").slideDown(300); $("#auth_block").css({"border-bottom":"2px solid #ffffff"}); flag = 1; } else { $("#auth_form").slideUp(300); $("#auth_block").css({"border-bottom":"none"}); flag = 0; } }); });
and the block itself:
<div class="info_block" id="auth_block"> <div id="top_name">Авторизация</div> <div id="auth_form"> <div id="text_info">Логин</div> <input type="text" name="auth_login"> <div id="text_info">Пароль</div> <input type="password" name="auth_pass"><br> <input type="submit" name="auth_sub" value="Войти"> <a href="javascript://" id="goto_reg">Регистрация</a> </div> </div>
Thank you in advance!
.stop()
at the beginning of the handler. - etki