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
-
stris aDOMString
Return value
-
itemis aRadioNodeList,Element, ornull.
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 |
25 |
79 |
33
27-33
Returned a
NodeList instead of a RadioNodeList. |
No |
15 |
7 |
≤37 |
25 |
33
27-33
Returned a
NodeList instead of a RadioNodeList. |
14 |
7 |
1.5 |
See also
-
HTMLCollection.namedItemthat it replaces
© 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