Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

281
Visualizações
How can i get rid of EventListener error?

I have spend many hours trying to debug this error

this is the code:

an array with objects

var reviews = [
{
    id:1,
    name:"Sarah Doe",
    img:
    "https://res.cloudinary.com/diqqf3eq2/image/upload/v1586883334/person-1_rfzshl.jpg",
},
{
    id:2,
    name:"Clara Doe",
    img:
    "https://res.cloudinary.com/diqqf3eq2/image/upload/v1586883409/person-2_np9x5l.jpg",

}

]

var img1 = document.getElementById("img");
var nextBtn = document.querySelector(".nextbtn");
var currentItem = 0;

window.addEventListener('DOMContentLoaded',function(){
        var item = reviews[currentItem];
        img.src = item.img;
        
        
})

function ShowImage(){
    var item1 = reviews[currentItem];
    img.src = item1.img;
}
nextBtn.addEventListener('click',function(){
    showImage(currentItem);
    currentItem++;
});

and this is the Html code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="app.js"></script>
</head>
<body>
        <img id="img" src="" alt="">
    <button class="nextbtn">Next</button>
</body>
</html>

the error shows up here:

nextBtn.addEventListener('click',function(){
    showImage(currentItem);
    currentItem++;
});

i've got this error in the console

the error is:ERROR

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda