by
0
4
167k
0
Top 1% !
Popular
Pearl of Wisdom
Specified
Popularity: 10892nd place
No tags for this snippet yet.
LanguageJavaScript
LicenseMIT_X11
SourceGitHub
SourceMyGists
TechnologyJQuery

addClass function similar to Jquery

addClass function similar to Jquery: 
addClass.js
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/267377/addClass-function-similar-to-Jquery?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
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");
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus