I like to close box by cliking out side of the box.
First 2 scripts are open/close and some decoration of button.They works fine.
Now, on 3rd script, Im trying to close box by cliking out side of the box while box are opening.
It keeps opening and closing like crashed website once I click it now.
It would be much appreciated to hear any help. Thank you.
//1st script to open and close
<script>
$(function(){
$(".ddd").css("display","none");
$(".button-toggle").on("click", function() {
$(".ddd").slideToggle();
});
});
</script>
//2nd script for decoration
<script>
$(function(){
var flg = "off";
$('.button-toggle').on('click', function(){
if(flg == "off"){
$(this).html("<div>close</div>");
flg = "on";
}else{
$(this).html("");
flg = "off";
}
});
});
</script>
//3rd script to close box by cliking out side of the box.
<script>
$(function() {
var flg = "on";
$(document).click(function() {
if(flg == "on"){
$(".button-toggle").click();}
flg = "off";
});
});
</script>
<div class="wrap">
<div class="button-toggle">
<div>buttons</div>
</div>
<div class="ddd">
<ul>
<li>
BUTTON A
</li>
<li>
BUTTON B
</li>
</ul>
</div>
</div>