javascript getElementsByTagName

getElementsByTagName

The document.getElementsByTagName(name) is a method of the document object that is used to get an element by its tag name.

Syntax:

document.getElementsByTagName(name)

Example:

<!DOCTYPE html>
<html>
<body>
<h1>"Get Element by Tag Name!"</h1>
<p>Example</p>
<p id="DOM"></p>
<script>
var x = document.getElementsByTagName("h1");
document.getElementById("DOM").innerHTML =
'The text in h1 is: ' + x[0].innerHTML;
</script>
</body>
</html>