Created
August 19, 2014 01:56
-
-
Save sTiLL-iLL/ebe43d12453d7fd39473 to your computer and use it in GitHub Desktop.
addClass function similar to Jquery
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(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