Wednesday, July 23, 2014

hide a DIV when the user clicks outside of it

hide a DIV when the user clicks outside of it
 
$(document).mouseup(function (e)
{
    var container = $("YOUR CONTAINER SELECTOR");

    if (!container.is(e.target) // if the target of the click isn't the container...
        && container.has(e.target).length === 0) // ... nor a descendant of 
//the container
    {
        container.hide();
    }
});
 
The magic is the not using click. 

1 comment:

Anonymous said...

Great !!!

You Done it Mr Mahesh :)