I am trying to do some for loop practice and apply the blue color style to all "listing" class with a click event. In addition to that, i also wanted to print the value of "i" in every loop. Can anyone point out what im missing in the code please. Thank you Here is my code:
function changeClass(){
for (i=0;i<3;i++) {
var list = document.getElementsByClassName("listing")[i];
list.style.color = "blue";
var values = document.getElementsByClassName("value");
document.write(i);
}
}
document.getElementById("change").addEventListener("click", changeClass);
<ul id="groupList">
<li class="listing">First</li>
<li class="listing">First</li>
<li class="listing">First</li>
<li class="value"></li>
</ul>
<button id="change">change listing</button>
values, the list of elements with the classvalue?