Document directory
- Syntax
- Description
- Example 1
- Example 2
- Example 3
Definition and usage
The getelementsbytagname () method returns a set of objects with the specified tag name.
Syntax
document.getElementsByTagName(tagname)
Description
The getelementsbytagname () method returns the order of elements in the document.
If you pass the special string "*" to the getelementsbytagname () method, it returns a list of all elements in the document. The order of elements is the order in the document.
Tips and comments
Note: strings passed to the getelementsbytagname () method can be case-insensitive.
Example 1
document.getElementsByTagName("input"); alert(x.length); }</script>Example 2
You can use the getelementsbytagname () method to obtain the list of HTML elements of any type. For example, the following code obtains all the tables in the document:
var tables = document.getElementsByTagName("table")
;alert ("This document contains " + tables.length + " tables");
Example 3
If you are familiar with the structure of the document, you can also use the getelementsbytagname () method to obtain a specific element in the document. For example, the following code obtains the fourth section of the document:
var myParagragh = document.getElementsByTagName("p")[3]
;
However, we still think that if you need to operate a specific element, the getelementbyid () method will be more effective.
Function queding () {var val = ""; var allclass =$ ('Type _ left '). getelementsbytagname ('img '); For (VAR I = 0; I <allclass. length; I ++) {If (allclass [I]. classname = "app-icon-seldw") {if (I <= 5) {Val + = "road construction -";} else if (I> = 14 & I <= 50) {Val + = "rural road-";} else if (I> = 53 & I <= 62) {Val + = "highway maintenance-";} else {Val + = "Other-";} Val + = allclass [I]. nextsibling. firstchild. nodevalue + ";";}}