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

168
Views
Function does not update the clock?

Function does not update the clock, how to properly delegate an event, how to fix it (https://jsfiddle.net/aod16pvj/7/) I tried this way (https://jsfiddle.net/jde9vp0t/), but delegation is needed

const timeInner = document.querySelector('[data-clock="time"]')
let AAstr, YY, MM, DD, AA, hh, mm, ss

function updateClock(date) {
  AAstr = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
  YY = date.getFullYear().toString().slice(-2)
  MM = date.getMonth() + 1
  DD = date.getDate()
  AA = date.getDay()
  hh = date.getHours()
  mm = date.getMinutes()
  ss = date.getSeconds()
  if (MM < 10) MM = '0' + MM
  if (DD < 10) DD = '0' + DD
  if (hh < 10) hh = '0' + hh
  if (mm < 10) mm = '0' + mm
  if (ss < 10) ss = '0' + ss
}

function clock() {
  let date = new Date()
  let delay = 1000 - new Date().getMilliseconds()
  updateClock(date)
}
clock()

document.querySelector('.options__format').addEventListener('input', (e) => {
  const chk = e.target.checked
  const chkId = e.target.dataset.chkId
  const itmChk = document.querySelector(`[data-clock="${chkId}"]`)
  timeInner.innerHTML = `${hh} : ${mm}`
  itmChk.innerHTML = ``
  if (chk) {
    if (chkId == 'date') itmChk.innerHTML = `${YY} - ${MM} - ${DD}`
    if (chkId == 'seconds') itmChk.innerHTML = `\u00A0: ${ss}`
    if (chkId == 'day') itmChk.innerHTML = `\u00A0${AAstr[AA]}`
  }
})
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!