Created
August 16, 2012 15:49
-
-
Save OndrejSlamecka/3371245 to your computer and use it in GitHub Desktop.
Manipulate DOM class with CoffeeScript
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
# DOM Class - based on http://www.openjs.com/scripts/dom/class_manipulation.php | |
class @DomClass | |
this.has = (el, className) -> | |
return el.className.indexOf(className) != -1 | |
this.add = (el, className) -> | |
if !this.has(el, className) | |
el.className += ' ' + className | |
this.remove = (el, className) -> | |
if this.has(el, className) | |
regex = new RegExp('(\\s|^)' + className + '(\\s|$)') | |
el.className = el.className.replace(regex, ' ') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment