I’m clicking on a checkbox to add some animation to a div, but when I want this animation to disappear I can only make it happen through $(document) click. Checkbox must add and then remove the class.
JS
$('#inOrder').click(function(e) {
$('.border').addClass('colorsborder');
e.stopPropagation();
$(document).click(function(e) {
$('.border').removeClass('colorsborder');
});
});
$('#inOrder').click(function(e) {
e.stopPropagation();
});
HTML
<input id="inOrder" type="checkbox" />
2
Answers
Then you want to toggle the class not add it when you click on checkbox
You may call
toggleClass()
method on thejQuery
object (element) that you want to add or remove the class from. The methodtoggleClass
will either:Here’s a basic, live demo to illustrate the functionality: