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

104
Views
forEach overlay showing the same content

I have a forEach showing a row of different images (fitness exercises) when you click on the image I want to show a clip of that exercise (gif).

But it doesn't show the same gif from the document of the image clicked on, it only shows the gif from the first document.

How do I make it so when you click on the image it shows the right gif from the same document.

I am collecting the image and gif from firestore.

Javascript Code

   const exgif = document.getElementById("exercise-gif");

                const e = query(collection(db, "user", uid, "yourWorkouts", id, "exercises"));
                const un = onSnapshot(e, (querySnapshot) => {

                    querySnapshot.forEach((doc) => {
                        // doc.data() is never undefined for query doc snapshots
                        console.log("exercises", doc.data());


                        const img = doc.data().image;
                        const exGif = doc.data().exGif;

                        exgif.innerHTML += `

                            <input type="image" id="toggle" src="${img}" class="ovr-ex-img" onclick="on()" />

                            <div id="over-exercise" onclick="off()">
                                <img class="ex-img" src="${exGif}">
                            </div>

                        `
                    });
                });  

function on() {
  document.getElementById("over-exercise").style.display = "block";
}

function off() {
  document.getElementById("over-exercise").style.display = "none";
}

HTML

<div class="" id="exercise-gif"></div>
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!