JS gets all elements of the same class name

Source: Internet
Author: User

Http://www.ipuman.com/pm1/s13/152/index.html

In a Web page, IDs are unique, and class can be reused. In some cases, some elements, we use the same class classname to keep them consistent, and when the current end needs to be processed dynamically, we want to be able to get them in class instead of giving them IDs. Here is a JS to get all the same class name elements of the function. View Source print?

01 function Getelementsbyclassname (className, Outid) {
02 var Obox = document.getElementById (Outid); Get element with ID Outid
03 THIS.D = Obox | | Document Detects whether a obox exists, and if not, assigns document to internal variables D
04 var children = this.d.getelementsbytagname (' * ') | | document.all; Get all elements of a page
05 var elements = new Array (); Defines an array that is used to store the resulting elements
06 Gets all elements of the element's class as ClassName
07 For (Var

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.