HTMLFormControlsCollection.namedItem()

The HTMLFormControlsCollection.namedItem() method returns the RadioNodeList or the Element in the collection whose name or id match the specified name, or null if no node matches.

Note that this version of namedItem() hides the one inherited from HTMLCollection. Like that one, in JavaScript, using the array bracket syntax with a String, like collection["value"] is equivalent to collection.namedItem("value").

Syntax

var item = collection.namedItem(str);
var item = collection[str];

Parameters

Return value

Example

HTML

<form>
  <input id="my-form-control" type="textarea">
</form>

JavaScript

// Returns the HTMLInputElement representing #my-form-control
elem1 = document.forms[0]['my-form-control'];

Specifications

Specification
HTML Standard (HTML)
# dom-htmlformcontrolscollection-nameditem-dev

Browser compatibility

BCD tables only load in the browser

See also