Skip to content

Instantly share code, notes, and snippets.

@koentjuh1
Created August 30, 2016 10:09
Show Gist options
  • Save koentjuh1/b84816ad6d1865007fec118412ea4800 to your computer and use it in GitHub Desktop.
Save koentjuh1/b84816ad6d1865007fec118412ea4800 to your computer and use it in GitHub Desktop.
Add class to parent and remove when clicked outside the element
<div class="click-box">
<div class="btn btn-default">click me</div>
<div class="click-content">
click content
</div>
</div>
$('html').click(function() {
$(".click-box .btn").parent().removeClass('click-box-open');
});
$('.click-box .btn').click(function(event){
$(this).parent().toggleClass('click-box-open');
});
$('.click-box').click(function(event){
event.stopPropagation();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment