Compatibility of Getelementsbyclassname

Source: Internet
Author: User

/*----------------------------index.html------------------------------------*/

<! DOCTYPE html>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<meta name= "Author" content= "Hehe" >
<title>shopping list</title>
<link rel= "stylesheet" type= "Text/css" href= "My_css.css" >
<body>
<p title= "A gentle reminder" >don ' t forgrt to buy this stuff.</p>
<ul id= "Purchases" >
<li>a Tin of Beans</li>
<li class= "Sale" >Cheese</li>
<li class= "Sale Important" >Milk</li>
</ul>
<script type= "Text/javascript" src= "My_script.js" ></script>
</body>

/*------------------------my_script.js------------------------*/

function Getelementsbyclassname (node,classname) {
if (node.getelementsbyclassname) {
return Node.getelementsbyclassname (classname);
}
else{
var results=new Array ();
var elems=node.getelementsbytagname ("*");
for (Var i=0;i<elems.length;i++) {
if (Elems[i].classname.indexof (className)!=-1) {
Results[results.length]=elems[i];
}
}
return results;
}
}

var Shopping=document.getelementbyid ("Purchases")
var itsems=getelementsbyclassname (Shopping, "sale");
for (Var i=0;i<itsems.length;i++) {
Alert (typeof Itsems[i]);
}

The page now displays a warning box for both objects.

Compatibility of Getelementsbyclassname

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.