IE does not support the Getelementsbyclassname solution

Source: Internet
Author: User
Tags tagname

At present, it can be resolved, the browser support does not support this method, if support is not, if not supported, in the Document object to add Getelementsbyclassname this method, according to interested friends can understand the next

if(Navigator.appname = = ' Microsoft Internet Explorer ') {Document.getelementsbyclassname=function() {              varTtagname = "*"; if(Arguments.length > 1) {Ttagname= Arguments[1]; }              if(Arguments.length > 2) {                  varPOBJ = arguments[2]              } Else {                  varPOBJ =document; }              varObjarr =Pobj.getelementsbytagname (ttagname); varTrobj =NewArray ();  for(vari = 0; i < objarr.length; i++) {                  if(Objarr[i].classname = = Arguments[0]) {Trobj.push (objarr[i]); }              }              returnTrobj; }      } 
functionGetelementsbyclassname (classname,tagname) {tagName=tagname| | " *";//parameter tagname can not be written.     if(Document.getelementsbyclassname) {//if the browser supports Getelementsbyclassname, use it directly        returnGetelementsbyclassname (className); }Else {         vartag= document.getElementsByTagName (tagName);//gets the specified element        varTagall = [];//for storing elements that meet the criteria         for(vari = 0; i < tag.length; i++) {//iterating through the acquired elements             for(varJ=0,n=tag[i].classname.split ("); j<n.length;j++) {//iterates through the values of all classes in this element, and assigns a value to Tagnameall if it contains the specified class name                if(n[j]==className)                    {Tagall.push (tag[i]);  Break; }            }        }        returnTagall; }}

IE does not support the Getelementsbyclassname solution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.