I have a problem with parent.getElementsByClassName() in javascript. I am working on a slider and wanted to count how many slides are put into it, but I've encountered a massive problem.
From my understanding, this command should make an array of all objects with a selected class name, but it's not working properly in my case. Whenever I put this code into my .js file it doesn't want to coop.
let slides = document.getElementsByClassName("slide") ;
console.log(slides); // returns HTMLCollection[]
// 0:div#id1hehe.slide
// 1: div.slide
and when I do
console.log(slides[0]);
it returns undefined.
When I put the same code into the browser console I get:
console.log(slides) // HTMLCollection(2) [div#id1hehe.slide, div.slide, id1hehe: div#id1hehe.slide]
and
console.log(slides[0]) // <div class="slide" id="id1hehe" style="margin-left: -89.0215%;">...
Can someone explain why is it like this?
` tag.
– T.J. Crowder Aug 01 '20 at 12:44