Created
May 20, 2015 14:27
-
-
Save jdavidbakr/d50874bd6efe074a0adb to your computer and use it in GitHub Desktop.
JavaScript: Class Management
This file contains hidden or 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
function addClass(el, className) { | |
if (el.classList) | |
el.classList.add(className); | |
else | |
el.className += ' ' + className; | |
} | |
function removeClass(el, className) { | |
if (el.classList) | |
el.classList.remove(className); | |
else | |
el.className = el.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' '); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment