Created
October 2, 2016 18:29
-
-
Save getanwar/78fd63e964275240ac3905b1a5068853 to your computer and use it in GitHub Desktop.
JS: Toggle Class JS
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
var toggleClass = function(element, toggleClass) { | |
var currentClass = element.className; | |
if (currentClass.indexOf(toggleClass) > -1) { //has class | |
var newClass = currentClass.replace(toggleClass, "") | |
} else { | |
var newClass = currentClass + " " + toggleClass; | |
} | |
element.className = newClass; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment