Created
September 5, 2016 10:50
-
-
Save Dinir/bbe03d0ea5c7ed3ee0bdc06d9252e5e7 to your computer and use it in GitHub Desktop.
Change DOM classes quickly.
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
const changeClass = (target, firstCl, secondCl) => { | |
// if first exist = add it | |
// if both exist = change first to second | |
// if both exist and first is * = overwrite with second | |
if(firstCl) { | |
if(!secondCl) { | |
target.className += ` ${firstCl}`; | |
} else { | |
target.className = firstCl==="*"? | |
secondCl: | |
target.className.replace(new RegExp('\\s?'+firstCl), secondCl); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment