I want the user to be able to click on the words “Click Here” and toggle between showing/hiding the drop down. This works fine. I also want the user to be able to click outside of the drop down area and hide the drop down menu if it is currently displayed. How do I do this?
jquery:
function dropDown() {
$(document).ready(function(){
$('#myID').load('my_file.php',function(){
document.getElementById("myID").style.visibility="visible";
$('#myID').slideToggle('fast');
})
return false;
});
}
HTML:
<div onclick="dropDown()">Click Here</div>
<div id="myID"></div>
CSS:
#myID {
visibility:hidden;
z-index:9999;
display:none;
}
Remove the
visibility:hiddenattribute from the codeAttach the click handlers for both the
divand thedocumentCSS
Check Fiddle
If you want to use
visibility:hiddenin your code then you need to omit thedisplay:noneand vice versa…