I have created a small plugin to show a dropdown menu when a div is clicked.
Below is the code to get it to work
$('#clickable_div').click(function() {
$('#nav_menu').showMenu({
parent:'#clickable_div'
});
});
Jsfiddle with the plugin : http://jsfiddle.net/HtNK3/
So now basically i want to add a functionality where i need to hide the dropdown div when user clicks anywhere in the document but not on the dropdown div which is open
How can this be achieved ?
I am using something like this:
//Close popup menus by clicking anywhere
$("body").mouseup(function(event){
if (!$(event.target).hasClass("YOUR_CLASS_HERE")) {
$("#nav_menu").hide();
}
});
I would use setTimout when the mouse leaves the dropdown (mouseleave
event) and then hide the div. Pretty common and easy.
Buggy but basic example: http://jsfiddle.net/HtNK3/5/
if ($(event.target).id != "nav_menu")
Ilia Frenkel 2012-04-05 02:41