Compatible with IE8 and below Getelementsbyclassname () methods
1 2 functionGetelementsbyclassname =function(ClassName, tagName) {3 //if the browser supports Getelementsbyclassname (), return directly4 if(document.getelementsbyclassname) {5 returndocument.getelementsbyclassname (className)6 }7 //otherwise traverse the label name collection specified by the document file8 varChildren =document.getElementsByTagName (tagName);9 //this array holds the class elements that are obtained after the traversalTen varelements =NewArray (); One A for(vari = 0; i < children.length; i++) { - varChild =Children[i]; - varClassnames = Child.className.split (");//split multiple class elements the for(varj = 0; J < Classnames.length; J + +) { - if(Classnames[j] = =className) { - Elements.push (child); - Break; + } - } + } A returnelements; at};
Getelementsbyclassname () method compatible with IE