I've setup a carousel with Materialize framework, now i would like to show some text with the mouseenter event, but it's seems it doesn't work. the display of my text is still none, and i have an error "TypeError: infos[i] is undefined".
The console.log(infos[i]) is working and the concerned divs have the display none attributes so i guess the problem comes from the line elem.addEventListener('mouseenter', function(){ infos[i].style.display="block" })
M.AutoInit();
document.addEventListener('DOMContentLoaded', function () {
let interval = null
const timeInterval = 5000
const elem = document.querySelector('.carousel')
const carousel = M.Carousel.getInstance(elem, {
indicators: true
})
const iterate = () => carousel.next()
const init = () => setInterval(iterate, timeInterval)
interval = init()
elem.addEventListener('mouseenter', () => clearInterval(interval))
elem.addEventListener('mouseleave', () => {
interval = init()
})
var infos = document.querySelectorAll('.infos');
for (i = 0; i<infos.length;i++){
infos[i].style.display="none"
//console.log(infos[i])
elem.addEventListener('mouseenter', function(){
infos[i].style.display="block"
})
}
})