This is my 1th technical note, to share with you: Solve IE8 (and below) does not support the Getelementsbyclassname method. If there is a wrong place, please tell me the message, I corrected in time, one is to update my cognition, and secondly also do not mislead others, thank you.
When we set the style of the element, we can say that the most used is the class. Unfortunately, in the low version of IE (IE8 and below), we cannot use getelementsbyclassname because IE does not add this method to the Document object.
This result is false in IE8 and in the following versions
Console.info (' Getelementsbyclassname ' in window.document);
Below, share my getElementsByTagName's compatible wording:
/*parameter description: obj parameter: A DOM object, the GetClass function obtains all the element nodes under this object. Sclass: A string that gets the class name of the element. */ functionGetClass (obj,sclass) {//prepares an array to be returned as a result of a function call varAresult = []; //If there is getelementsbyclassname in the Docuemnt object, we will use the browser to provide
Because the browser provides more efficiency if(' Getelementsbyclassname 'inchdocument) {Aresult=Obj.getelementsbyclassname (Sclass); } //If the browser does not then we have to achieve a total of 4 steps Else{ //1. Get all the elements under obj varAele = Obj.getelementsbytagname (' * ')); //2. Check each child element with a for loop for(vari=0; i<aele.length; i++ ){ //3. Get each child element classname value This value is a string varstr =Aele[i].classname; //4. If the class attribute of the element has the class we need, then put it in Aresult. if(Str.indexof (Sclass)!=-1) {Aresult.push (aele[i]); } } } returnAresult; }
Resolves an issue where IE8 (and below) does not support Getelementsbyclassname