Get your own website Result Size: 625 x 565
x
 
<!DOCTYPE html>
<html>
<style>
div {
  border: 1px solid black;
  padding:16px;
}
</style>
<body>
<h1>The Element Object</h1>
<h2>The getElementsByClassName() Method</h2>
<div id="myDIV">
  <p class="child">I am a paragraph.</p>
  <p class="child">I am a paragraph.</p>
  <p class="child">I am a paragraph.</p>
</div>
<p>The number of elements with class "child" are:</p>
<p id="demo"></p>
<script>
const element = document.getElementById("myDIV"); 
const nodes = element.getElementsByClassName("child");
document.getElementById("demo").innerHTML = nodes.length;
</script>
</body>
<!-- Mirrored from www.w3schools.com/jsref/tryit.asp?filename=tryjsref_element_getelementsbyclassname_length by HTTrack Website Copier/3.x [XR&CO'2014], Wed, 21 Dec 2022 17:39:44 GMT -->
</html>