So I've been trying to hide a navbar when the user clicks outside of it. I can't figure out why this function won't call. The full navbar is hidden outside of the screen (top -120px
). When the user clicks the open button, jquery changes the top to 0. I made it close back if the user clicks a link in the navbar, however, I tried to do the same thing if the user clicks out of it.
I tried using .click on the "content" div, but that didn't work either.
Here is a Fiddle with the whole navbar: https://jsfiddle.net/daxgnq07/
jQuery
$(document).mouseup(function (e) {
var container = $("header");
if (!container.is(e.target) && container.has(e.target).length === 0) {
container.css("top", "-120px");
container.css("margin-top", "0px");
}
});
HTML
<header>
<div id="navbar">
...
</div>
</header>
<div id="content">
</div>