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

223
Visualizações
Button are not connected in loop, but the last one is
function createTimer(countdownObject) {

    let id = countdownObject.Id
    let removeClass = "inline remove" //(isRemoveButtonsEnabled && "inline remove") || "inline remove hidden"

    document.getElementById("countdownList").innerHTML +=
        `
    <dt id = "` + id + `" class = "countdown">
    <h2 id = "` + id + `-title" class="title">Example Timer</h2>
    <h3 id = "` + id + `-daysNum" class = "time inline"></h3>
    <h3 id = "` + id + `-daysDesc" class = "time description inline">days</h3>
    <h3 id = "` + id + `-hoursNum" class = "time inline"></h3>
    <h3 id = "` + id + `-hoursDesc" class = "time description inline">hours</h3>
    <h3 id = "` + id + `-minsNum" class = "time inline"></h3>
    <h3 id = "` + id + `-minsDesc" class = "time description inline">minutes</h3>
    <h3 id = "` + id + `-secsNum" class = "time inline"></h3>
    <h3 id = "` + id + `-secsDesc" class = "time description inline">seconds</h3>
    <br>
    <input type="button" value="Delete" id = "` + id + `-remove" class="` + removeClass + `"></button>
    </dt>
    `

    const removeButton = document.getElementById(id + "-remove")

    console.log(removeButton)
    updateTimer(countdownObject)

    removeButton.onclick = function () {
        removeTimer(id)
    }()


}

function removeTimer(id) {
    for (let i = 0; i < countdowns.length; i++) {
        if (countdowns[i].Id == id) {
            countdowns.splice(i, 1)
        }
    }
    document.getElementById(id).remove()
    console.log(countdowns)
    saveCountdowns()
}

I'm trying to create this countdown widget. I'm running this function in a basic for loop and inputting a countdownObject with keys of Name, End and Id. There's a problem that only allows one of the buttons to work at a time (usually the last one created) and I have no idea why. The removeTimer function works perfectly, its just a problem of all the buttons not getting connected to the onclick event.

Visual

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