For example, if we want to find those elements in a <body> element that are <li>, we could use this method as:
Note: here the bodyElement is a reference to the <body> tag in the document. Now with this statement, those <li> elements in the document that are the descendants of the <body> element will be returned as the items in a collection object.
Element getElementsByTagName() Method Syntax:
Element getElementsByTagName() Method Parameter
The method takes one argument and that is the name of the tag we’re looking for.
Element getElementsByTagName() Method Return Value
The return value of this method is a collection object and each of its items is a reference to an element that matched the requirements of the method.