Export (0) Print
Expand All
go
Expand Minimize

getElementsByName method

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

Syntax

var retval = document.getElementsByName(v);

Parameters

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

Remarks

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.

Examples

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


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

See also

document
About the W3C Document Object Model

 

 

Show:
© 2014 Microsoft