HTMLCollection namedItem() Method
- Previous Page length
- Next Page item()
- Go to the Previous Level DOM HTMLCollection
Definition and Usage
namedItem()
The method returns an element in the HTMLCollection that has the specified ID or name.
You can also use a shorthand method and it will produce the same result:
var x = document.getElementsByTagName("P")["myElement"];
Example
Get the content of the P element with ID "myElement":
function myFunction() { var x = document.getElementsByTagName("P").namedItem("myElement"); alert(x.innerHTML); }
Syntax
HTMLCollection.namedItem(name)
Or:
HTMLCollection[name]
Parameter value
Parameter | Description |
---|---|
name | Required. The value of the id attribute or name attribute of the element to be returned. |
Return value
Element objectRepresents an element with a specified ID or name.
Returns null if the element does not exist.
Browser Support
Method | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
namedItem() | Support | Support | Support | Support | Support |
- Previous Page length
- Next Page item()
- Go to the Previous Level DOM HTMLCollection