I have implemented a dropdown menu that appears when inline text links are clicked. The jQuery click event is used to show the dropdown menu upon clicking a link.
My goal is to make the dropdown menu revert to a hidden state when a click is made anywhere on the page. Currently, you have to click the link again to close the menu.
Check out the demo here
Here is the jQuery code:
// Show Dropdown Menu when link is clicked
$(function(){
$(".inline-dropdown-menu").click(function(e){
$(this).find(".inline-dropdown-menu-list:first").toggle();
e.preventDefault(); // Stop navigation
});
});
And here is the HTML markup:
<span class="inline-dropdown-menu">
<a href="">My Link that reveals a DropDown Menu when clicked on<span class="caret"></span></a>
<ul class="inline-dropdown-menu-list">
<li class="bottomBorder">
<a href="" tabindex="-1">alphabetically</a>
</li>
<li>
<a href="" tabindex="-1">2. the first report, alphabetically</a>
</li>
<li>
<a href="" tabindex="-1">3. the first report, alphabetically</a>
</li>
</ul>
</span>