<!DOCTYPE html>
<html>
<body>
<div id="myDiv">
<p>the first paragraph</p>
<p>the second paragraph</p>
<p>the third paragraph</p>
</div>
<p>click the button to see how many element with TagName p in div:</p>
<button onclick="myFunction()">click</button>
<script>
document.write(x.length);
function myFunction() {
var x = document.getElementById("myDiv").getElementsByTagName("p");
document.write(x.length);
}
</script>
</body>
</html>