CodesJava

Easy learning with example program codes

javascript getElementsByTagName

getElementsByTagName

The document.getElementsByTagName(name) is a method of the document object which 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>
Please follow and like us:
error








Copyright © 2019 CodesJava DMCA.com Protection Status