To correctly iterate through getElementsByClassName with JavaScript, we use a for-of loop.
For instance, we write
const slides = document.getElementsByClassName("slide");
for (const slide of slides) {
console.log(slide);
}
to call getElementsByClassName
to select all elements with class slide
.
Then we use a for-of loop to loop through all the slides
and log its value.