English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML DOM getElementsByName() method

HTML DOM Document Object

getElementsByName()A group of element node objects can be obtained by using the name attribute, and this method is supported by all browsers.

The elements in the returned list are sorted in the order they appear in the source code.

elements in the returned list can be accessed by index number. The index starts from 0.

used for arrayslengthThe attribute determines the number of elements with the specified name, and then all elements can be traversed to extract the required information.

Syntax:

document.getElementsByName(name)
var x = document.getElementsByName("demo");
Test See‹/›

Browser Compatibility

All browsers fully support the getElementsByName() method:

Method
getElementsByName()YesYesYesYesYes

Parameter Value

ParameterDescription
nameThe value of the element's name attribute

Technical Details

Return Value:Returns an array-like object containing all child elements with the given name.
DOM Version:DOM Levels1

Related References

DOM Document querySelector()Methods

DOM Document querySelectorAll()Methods

DOM Document getElementById()Methods

DOM Document getElementsByTagName()Methods

HTML DOM Document Object