javascript - hide div menu when clicking somewhere else -
When I click elsewhere on the page, then my goal is to disappear. Below is the code that opens my code and closes when two divs click on themselves.
var content_nav = ''; Var content_select = ''; Window.onload = function () {content_nav = document.getElementById ("content_nav"); Content_select = document.getElementById ("content_select"); Content_nav.addEventListener ("click", show_or_hide); } Function show_or_hide () {if (content_select.style.display! = "Block") content_select.style.display = "block"; Else content_select.style.display = "none"; }
You should listen to click events on the whole page and hide the menu Was out of content_nav, try it (you may need to zoom it to work, I do not know your HTML):
$ (document) .click (function ( E) {If $ (E.target) .closest ('# content_nav') length) $ ('# content_nav'). Hide ();});
Comments
Post a Comment