vardropdownMenuDiv=document.getElementById("menuDiv-dropdown");vardropdownMenu=document.getElementById("menu-dropdown");// hide popup div when clicking outside the div// http://www.webdeveloper.com/forum/showthread.php?t=98973document.onclick=check;// Event accessing// http://www.quirksmode.org/js/events_access.html// Event properties// http://www.quirksmode.org/js/events_properties.htmlfunctioncheck(e){vartarget=(e&&e.target)||(event&&event.srcElement);if(!checkParent(target,dropdownMenuDiv)){// click NOT on the menuif(checkParent(target,dropdownMenu)){// click on the linkif(dropdownMenuDiv.classList.contains("invisible")){// Dynamically retrieve Html element (X,Y) position with JavaScript// http://stackoverflow.com/questions/442404/retrieve-the-position-x-y-of-an-html-elementdropdownMenuDiv.style.left=dropdownMenu.getBoundingClientRect().left+'px';dropdownMenuDiv.classList.remove("invisible");}else{dropdownMenuDiv.classList.add("invisible");}}else{// click both outside link and outside menu, hide menudropdownMenuDiv.classList.add("invisible");}}}functioncheckParent(t,elm){while(t.parentNode){if(t==elm){returntrue;}t=t.parentNode;}returnfalse;}