dom / latest / htmlformcontrolscollection / nameditem.html /

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

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
namedItem
1
12
33
27-33
Returned a NodeList instead of a RadioNodeList.
No
≤12.1
≤4
1
18
33
27-33
Returned a NodeList instead of a RadioNodeList.
≤12.1
1
1.0

See also

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormControlsCollection/namedItem