![]() |
VOOZH | about |
The getElementsByName() method returns collection of all elements of particular document by name. This collection is called node list and each element of the node list can be visited with the help of the index.
Syntax:
document.getElementsByName(name)
Parameter:This function accepts name of document.
Return Type:This function returns collection of elements. By using the build in method length we can find the total number of elements presents inside that particular element. Below example illustrates it clearly.
Note:There is no getElementByName() method exists, it is getElementsByName(), with a āsā.
Example-1:
Output:
Since document.getElementsByName() method returns an array containing of objects if we want to get value of any object then we should use document.getElementsByName("element_name")[index].value. Otherwise we will get result undefined. Below program explains it clearly.
Output:
Supported Browsers: The browser supported by DOM getElementsByName() method are listed below: