HTMLCollection namedItem() Method

The namedItem() method returns the element with the specified ID or name.

This example uses a shorthand method for the namedItem() method

Click the button to return the content of the P element with ID "myElement":