JS Native Package GetClassName () method-ie does not support getelementsbyclassname, so it's up to you to get all the elements with the class name classname

Source: Internet
Author: User
Tags tag name tagname

  

"Text/javascript">Window.onload =function () {var Topmenus = GetClass (‘Li‘,‘Topmenu‘);Forvar i=0;i < Topmenus.length; i++{alert (topmenus[i].innerhtml);}} function GetClass (tagname,classname)//Gets the element with the tag name tagname, class name classname{if (document.getelementsbyclassname)//Support this function{ReturnDocument.getelementsbyclassname (ClassName); }Else{var tags=document.getelementsbytagname (tagName);//Get tagsvar tagarr=[];//Used to return an element with the class name classnameForvar i=0;i < Tags.length; i++) {if (Tags[i].class = =ClassName) {Tagarr[tagarr.length] = tags[i];//Save an element that satisfies a condition} }ReturnTagarr; }}</script>"Nav"><liclass="Topmenu"><a href="#"> Product introduction </a> <ulclass="Submenu"> <li><a href="#"> Products 1</a></li> <li><a href="#"> Products 2</a></li> <li><a href="#"> Products 3</a></li> <li><a href="#"> Products 4</a></li> <li><a href="#"> Products 5</a></li> <li><a href="#"> Products 6</a></li> </ul></li><liclass="Topmenu"><a href="#"> Service Introduction </a> <ulclass="Submenu"> <li><a href="#"> Service 1</a></li> <li><a href="#"> Service 2</a></li> <li><a href="#"> Service 3</a></li> <li><a href="#"> Service 4</a></li> </ul></li><liclass="Topmenu"><a href="#"> Success Stories </a> <ulclass="Submenu"> <li><a href="#"> Case 1</a></li> <li><a href="#"> Case 2</a></li> <li><a href="#"> Case 3</a></li> <li><a href="#"> Case 4</a></li> </ul></li><liclass="Topmenu"><a href="#"> About Us </a> <ulclass="Submenu"> <li><a href="#"> We 1</a></li> <li><a href="#"> We 2</a></li> <li><a href="#"> We 3</a></li> <li><a href="#"> We 4</a></li> </ul></li><liclass="Topmenu"><a href="#"> Contact Us </a> <ulclass="Submenu"> <li><a href="#"> Contact 1</a></li> <li><a href="# "#" > Contact 3</a> </li> <li><a href= "# "> Contact 4</a></li> <li><a href=" # "#" > Contact 6</a> </li> <li><a href= "# "> Contact 7</a></li> </ul></li></ul></body>   

Note that both Getelementsbyclassname and getElementsByTagName have s;

JS can not use int a=1; a=1 with var;

JS Native Package GetClassName () method-ie does not support getelementsbyclassname, so it's up to you to get all the elements with the class name classname

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.