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

215
Views
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
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!