Skip to content

Instantly share code, notes, and snippets.

@sTiLL-iLL
Created August 19, 2014 01:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sTiLL-iLL/ebe43d12453d7fd39473 to your computer and use it in GitHub Desktop.
Save sTiLL-iLL/ebe43d12453d7fd39473 to your computer and use it in GitHub Desktop.
addClass function similar to Jquery
function addClass(node, class) {
if (!node.length) node = [node];
for (var n = 0, m = node.length; n < m; n++) {
if ((" " + node[n].className + " ").indexOf(" "+class+" ") >= 0) {
node.className += " " + class;
}
}
}
// apply myclass to all nodes
addClass(document.getElementById("myelement"), "myclass");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment