<html>
<head>
</head>
<body>
<h1>HTMLCollection length Property</h1>
<p>A P element.</p>
<p class="myclass">Another P element.</p>
<p class="myclass">A third P element.</p>
<p>Click the button to add a background color to all elements with class="myclass":</p>
<button onclick="myFunction()">Set Color</button>
<script>
function myFunction() {
var x, i;
x = document.getElementsByClassName("myclass");
for (i = 0; i < x.length; i++) {
x[i].style.backgroundColor = "red";
}
}
</script>
</body>
<!-- Mirrored from www.w3schools.com/jsref/tryit.asp?filename=tryjsref_htmlcollection_length_loop by HTTrack Website Copier/3.x [XR&CO'2014], Mon, 27 Jan 2020 03:03:05 GMT -->
</html>