I have a div, I want to set it so that when I click on something else, it would hide the div.
So I did
$('body').click(function(){
if(loginOpened)
{
$('#loginWindow').animate({
'width':'0px',
'height':'0px'
},"fast");
}
loginOpened=false;
});
However, even when I click in the div itself the event is fired, is there anyway to prevent this?
You can stop it using
e.stopPropagation();if there is a click event bound to the<div />tag.See event.stopPropagation()
Otherwise you can check the target of the event inside the body click. Check whether
event.targetis the same as your div.See event.target