Use of the Getelementsbyclassname () property under IE browser

Source: Internet
Author: User

Q:getelementsbyclassname () in IE browser but normal use, display Web page script error.

A: In the JS file to add the following processing code, it can be a perfect solution to this problem.

//solve the problem that IE cannot use the Getelementsbyclassname () method//if the browser cannot use document. getelementsbyclassname ()    if(!document.getelementsbyclassname) {//then give the following value to the GCDocument.getelementsbyclassname =function(ClassName, Element) {//Take out all the elements in a file or document         varChildren = (Element | | document). getElementsByTagName (' * ');//Create a new array             varelements =NewArray ();//iterate through all the elements                for(vari=0; i<children.length; i++){//assign the element to child for easy access to classname                        varChild =Children[i];//Considering that the element has multiple classname                        varClassnames = Child.className.split (");  for(varj=0; j<classnames.length; J + +){//If the classname is the same as to be taken, then put in a new array                            if(Classnames[j] = =className)                                {Elements.push (child);  Break; }                        }                    }                    returnelements;            }; }

Use of the Getelementsbyclassname () property under IE browser

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.