I've been experimenting with trying to retrieve elements by class name from the DOM using TypeScript. Despite what seems like a straightforward approach, I'm encountering an error in the console.
function showSlides() {
var i;
var slides = <HTMLElement[]<any>document.getElementsByClassName('slide');
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
}
Expected behavior is to have an array with 3 items and to change the display style to none, however the actual outcome is a JS error:
Uncaught TypeError: Cannot read property 'style' of undefined.