Created
January 8, 2012 20:56
-
-
Save Victa/1579658 to your computer and use it in GitHub Desktop.
addClass Function
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
| var addClass = function addClass(_element, _classes) { | |
| var classList, item, _i, _len; | |
| classList = _element.classList; | |
| for (_i = 0, _len = _classes.length; _i < _len; _i++) { | |
| item = _classes[_i]; | |
| classList.add(item); | |
| } | |
| return _element; | |
| }; | |
| // Usage | |
| // <div id="changeme" class="big red"></div> | |
| // <button onclick="addClass('changeme', 'round')">Add a class</button> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment