Created
June 5, 2013 11:10
-
-
Save yarysh/5713156 to your computer and use it in GitHub Desktop.
addClass function for JavaScript
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(o, c){ | |
| var re = new RegExp("(^|\\s)" + c + "(\\s|$)", "g"); | |
| if (re.test(o.className)) return; | |
| o.className = (o.className + " " + c).replace(/\s+/g, " ").replace(/(^ | $)/g, ""); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment