Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

272
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!