I have a div inside form something like
You can do what you want like this:
$(document).click(function() {
$("#idshow").hide();
});
$("#idshow").click(function(e) {
e.stopPropagation();
});
What happens here is when you click, the click
event bubbles up all the way to document
, if it gets there we hide the <div>
. When you click inside that <div>
though, you can stop the bubble from getting up to document
by using event.stopPropagation()...so the .hide() doesn't fire, short and simple :)
$(document).click(function(event) {
var target = $( event.target );
// Check to see if the target is the div.
if (!target.is( "div#idshow" )) {
$("div#idshow").hide();
// Prevent default event -- may not need this, try to see
return( false );
}
});