Created
August 30, 2016 10:09
-
-
Save koentjuh1/b84816ad6d1865007fec118412ea4800 to your computer and use it in GitHub Desktop.
Add class to parent and remove when clicked outside the element
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="click-box"> | |
<div class="btn btn-default">click me</div> | |
<div class="click-content"> | |
click content | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('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