This script makes it so when you click on a <div>
another <div>
appears by adding class log_in_box_dd
to #big_ul_hide
. Once #big_ul_hide
has that class, clicking anywhere (except the #big_ul_hide
will remove that class, thus hiding it.
So you click to see a pop-up div, then click anywhere but that div should hide it.
This whole thing works, but only once. After that it gets really weird.
After it's added and then removed,
inspecting elements will read <div id="big_ul_hide" class="">
. I can't get the class to re-add.
I have added the setTimeout
function so it won't doesn't remove the class immediately when .lin_und
is clicked.
So, why is it not letting me re-add the class? If I alert(...)
after the .toggleclass
it will alert every time, but still not apply the class.
fiddle: http://jsfiddle.net/NQxAC/
<script>
$('.lin_und').click(function() {
$('#big_ul_hide').toggleClass('log_in_box_dd');
});
setTimeout(function() {
$('html').click(function() {
if($('#big_ul_hide').hasClass('log_in_box_dd')) {
$('#big_ul_hide').removeClass('log_in_box_dd');
}
});
$('#big_ul_hide').click(function(event) {
event.stopPropagation();
});
}, 2000);
</script>
setTimeout
.Please take them out of crap – Rashidarashidi