Get your own website Result Size: 625 x 565
x
 
<!DOCTYPE html>
<html>
<body>
<h1>The HTMLCollection Object</h1>
<h2>The namedItem() Method</h2>
<p id="myElement">The namedItem() method returns the element with the specified id or name.</p>
<p>Click "Get" to get the content of the p element with id="myElement":</p>
<button onclick="myFunction()">Get</button>
<p id="demo"></p>
<script>
function myFunction() {
  const collection = document.getElementsByTagName("p");
  const element = collection.namedItem("myElement");
  document.getElementById("demo").innerHTML = element.innerHTML;
}
</script>
</body>
<!-- Mirrored from www.w3schools.com/jsref/tryit.asp?filename=tryjsref_htmlcollection_nameditem by HTTrack Website Copier/3.x [XR&CO'2014], Mon, 05 Sep 2022 15:19:30 GMT -->
</html>