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

105
Visualizações
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
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