I have created a dropdown with 2 options, menuitem1 and menuitem2 .But the dropdown is not hiding when I click outside.
As per the click()
function, the dropdown is hiding when I click itself. Where should I add $('#listdown').hide('slow')
code?
I have written the following code in JavaScript:
$(function(){
$(document).click(function(){
$('#listdown').hide('slow');
});
$("#listdown").click(function(e){
e.stopPropagation();
});
});
function click_gearbox(e)
{
var gear_box = document.getElementById('gearbox');
gear_box.style.display = 'none';
if (gear_box.style.display == "none") {
// Getting the actually position of the mouse
list_down.style.top = e.clientY + 'px';
list_down.style.left = e.clientX + 'px';
list_down.style.display ='block';
gear_box.style.display = 'block';
}
$('.dropdown-menu');
}
HTML :
<body>
<p id="on_body"></p>
<div id= "gearbox" class="dropdown" >
<a class="dropdown-menu" data-toggle="dropdown" href="#"></a>
<ul id = "listdown" class="dropdown-menu" role="menu" aria-labelledby="showgear">
<li role="presentation"><a role="menuitem1" tabindex="-1" href="#">list1</a></li>
<li role="presentation" class="divider"></li>
<li role="presentation"><a role="menuitem2" tabindex="-1" href="#">list2</a></li>
</ul>
</div>
</body>