When you trying to do the simple hide div when you click on the any part of the page. I got the trick after googling to to hide the div using JQuery.
HAS() method constructs a new jQuery object from a subset of the matching elements. The supplied selector is tested against the descendants of the matching elements; the element will be included in the result if any of its descendant elements matches the selector.
Hide Div when Click Outside - Trick
Jquery code
$(document).mouseup(function (e)
{
var loginBox = $("#login");
if (loginBox.has(e.target).length === 0)
{
loginBox.hide();
}
});
HTML Code
<div id="login"></div>
No comments:
Post a Comment