Skip to content

Instantly share code, notes, and snippets.

@tessalt
Last active December 13, 2015 20:08
Show Gist options
  • Save tessalt/4968149 to your computer and use it in GitHub Desktop.
Save tessalt/4968149 to your computer and use it in GitHub Desktop.
dropdowns
<div class="dropdown">
<a href="#" class="dropdown-trigger">Trigger Dropdown</a>
<ul class="dropdown-content">
<li><a href="#">Item 1</a></li>
<li><a href="#">Item 2</a></li>
</ul>
</div>
function dropdowns(){
$(".dropdown-trigger").click(function() {
$(this).next(".dropdown-content").toggleClass("show");
return false;
});
$("html").click(function() {
$(".dropdown-content").removeClass("show");
});
$(".dropdown, .dropdown-trigger, .dropdown-content").click(function(event) {
return event.stopPropagation();
});
}
dropdowns();
.dropdown {
position: relative;
}
.dropdown-content {
display: none;
position: absolute;
list-style: none;
z-index: 15;
&.show {
display: block;
}
a {
display: block;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment