VOOZH about

URL: https://www.geeksforgeeks.org/javascript/html-dom-getelementsbyname-method/

⇱ HTML DOM getElementsByName() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

HTML DOM getElementsByName() Method

Last Updated : 13 Jun, 2023

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:

 šŸ‘ Image
 

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:

 šŸ‘ Image
 

Supported Browsers: The browser supported by DOM getElementsByName() method are listed below:

  • Chrome 1
  • Edge 12
  • Internet Explorer 5
  • Firefox 1
  • Opera 5
  • Safari 1
Comment
Article Tags:
Article Tags: