Get GetElementsByTagName according to tag name.
getElementsByName()
This is to get an element by name. I don't know if you have noticed it. This is the GET element, and the plural element means that you didn't get an element. Why?
Because the ID of each element in the document is unique, but the name can be repeated. Metaphorically, it's like a person's ID number is unique (in theory, although it is repeated in reality), but the name.
There are many repetitions. If there are more than two tags with the same name in a document, getElementsByName () can make these elements form an array.
For example, there are two divs:
& ltdiv name = " docname " id = " docid 1 " >& lt/div & gt;
& ltdiv name="docname" id="docid2 " >& lt/div & gt;
Then you can use getElementsByName("docname ") to get these two divs, use getElementsByName ("docname ") [0] to access the first div, and use getelementsbyname.
getElementsByTagName()
In this case, the element is obtained by TAGNAME. Of course, there will be the same tags in a document, so this method also gets an array.
The following example has two divs. You can access them with getElementsByTagName("DIV "), access the first DIV with getElementsByTagName("div")[0], and use
Getelementsbytagname ("DIV") [1] accesses the second div.