I'm using the following code to hide a div (named info) when you click outside of it:
$(document).click(function(e) {
if (e.target.id != 'info' && !$('#info').find(e.target).length) {
$("#info").fadeOut(300);
setTimeout(function() {
$("#info").html("Select an Item");
},300);
}; //if statement
}); //click function
What i'm trying to achieve is after the fadeOut is done, to place the text "Select an Item" in the div. However this SetTimeout is always executed; the div shows itself through another function, but it seems that this setTimeout function also triggers, immediately.
Why does this happen and how do you fix this?