Baseline Widely available
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")
.
name
A string which will be used to match against the name
or id
attributes of the controls in this HTMLFormControlsCollection
object.
<form>
<label for="notes">Notes:</label>
<input id="notes" name="my-form-control" type="text" />
<label for="start">Start date:</label>
<input id="start" name="my-form-control" type="date" />
</form>
<div id="output"></div>
JavaScript
const form = document.querySelector("form");
const items = form.elements.namedItem("my-form-control");
const output = document.querySelector("#output");
const itemIDs = Array.from(items)
.map((item) => `"${item.id}"`)
.join(", ");
output.textContent = `My items: ${itemIDs}`;
Result Specifications Browser compatibility See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4