Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

getElementsByName method

Gets a collection of objects based on the value of the NAME or ID attribute.


var retval = document.getElementsByName(v);


v [in]

Type: BSTR

A String that specifies the value of a NAME attribute.

Return value

Type: IHTMLElementCollection

Returns a collection of objects with the same NAME attribute value.

Standards information


When you use the getElementsByName method, all elements in the document that have the specified NAME attribute or ID attribute value are returned.

Elements that support both the NAME attribute and the ID attribute are included in the collection returned by the getElementsByName method, but elements with a NAME expando are not included in the collection; therefore, this method cannot be used to retrieve custom tags by name.


This example uses the getElementsByName method to return a collection of input type=text elements with the specified NAME attribute value, firstName.

  function fnGetNames() {
    // Returns a collection with 2 INPUT type=text elements.
    var aInput = document.getElementsByName("firstName");
<input type="text" name="firstName">
<input type="text" name="firstName">
<input type="button" value="Get Names" onclick="fnGetNames()">

See also

About the W3C Document Object Model



© 2017 Microsoft