Skip to content

Instantly share code, notes, and snippets.

@Victa
Created January 8, 2012 20:56
Show Gist options
  • Select an option

  • Save Victa/1579658 to your computer and use it in GitHub Desktop.

Select an option

Save Victa/1579658 to your computer and use it in GitHub Desktop.
addClass Function
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