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

179
Visualizações
Cant make useful a button inserted in innerHTML for one function

I have one button that shows all my products in the webpage, each product is loaded from an array and inserted with innerHTML, each product is inserted with one button, i tried to assing one function for those buttons, but nothing happens:

Show.addEventListener('click', () => {
    flag = flag + 1
    if (flag == 2) {
        document.getElementById('ItemsID').disabled = true
    }
    console.log(ItemsID.options[ItemsID.selectedIndex].value)
    if (ItemsID.options[ItemsID.selectedIndex].value == "Vuelos") {
        document.getElementById('ShowItems').disabled = true
        VUELOSPROMOCIONES.forEach((VUELOSPROMOCIONES, indice) => {
            div_Vuelos.innerHTML += `
                   <div class="card" id="persona${indice + 1}" style="width: 18rem;">
                        <div class="card-body">
                            <h5 class="card-title">Vuelo Promocional ${indice + 1}</h5>
                            <p>Origen: ${VUELOSPROMOCIONES.origen}</p>
                            <p>Destino: ${VUELOSPROMOCIONES.destino}</p>
                            <p>Fecha Ida: ${VUELOSPROMOCIONES.FechaIda}</p>
                            <p>Fecha Vuelta: ${VUELOSPROMOCIONES.FechaVuelta}</p>
                            <p>Precio: ${VUELOSPROMOCIONES.precio}</p>
                        </div>
                    </div>
                    **<button id="Enviar">Click me</button>**
              `
        })
    } else if (ItemsID.options[ItemsID.selectedIndex].value == "Autos") {
        PROMOCIONESAUTOS.forEach((PROMOCIONESAUTOS, indice) => {
            document.getElementById('ShowItems').disabled = true
            div_Autos.innerHTML += `
                <div class="card" id="Autos Disponibles ${indice + 1}" style="width: 18rem;">
                    <div class="card-title">Persona ${indice + 1}</h5>
                        <p>Modelo: ${PROMOCIONESAUTOS.modelo}</p>
                        <p>Marca: ${PROMOCIONESAUTOS.marca}</p>
                        <p>Color: ${PROMOCIONESAUTOS.color}</p>
                    </div>
                </div>
                <button id="Enviar">Click me</button>
            `
        })
    }
    
})

if i insert the same button in the html, it works with the same id

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