Last active
October 10, 2021 20:28
-
-
Save treykane/db9378c0066fdb6938b0 to your computer and use it in GitHub Desktop.
Toggle a class, and remove the class when you click ANYWHERE ELSE on the document.
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
$( document ).ready(function() { | |
$(function() { // TOGGLE CLASS ON ELEMENT | |
$(".tile-top").on("click", function() { | |
$(this).toggleClass('active'); }); | |
}); //END TOGGLE CLASS | |
$(function() { // REMOVE CLASS WHEN YOU CLICK, EXCLUDE ELEMENTS | |
var ignore= Array(".tile-top", // elements to ignore | |
".tile-bottom"); | |
ignore.forEach(function (item) { // loop through ignore array | |
$(item).click(function(){ return false; }); // ignore item | |
}); | |
$(document).on("click", function() { // remove class when you click anywhere else | |
$(".tile-top").removeClass('active'); }); | |
});// END REMOVE CLASS | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! working like charm