The pure JS implementation selects the DOM based on the class of the CSS
- 2020-03-30 02:24:08
- OfStack
// online reference, modified a part of their own
// the following code, pure JS, requires the browser to support the getElementsByClassName method
// the following code, pure JS, requires the browser to support the getElementsByClassName method
<script type="text/javascript">
function getElementsByClassName(classname,node){
node = node || window.document;
if(node.getElementsByClassName){
return node.getElementsByClassName(classname);
}else{
var results = new Array();
var elems = node.getElementsByTag("*");
for (var i=0;i<elems.length;i++){
if(elems[i].className.indexOf(classname) != -1){
results[elems.length] = elems[i];
}
}
return results;
}
};
</script>