html - Countdown Timer in Javascript -


this question exact duplicate of:

i have little countdown code written in javascript html document. need someone's knowledge , modify code can input own time , start countdown button.

counter_start = 3  function tick () {     if (document.getelementbyid ('counter').firstchild.data > 0) {         document.getelementbyid ('counter').firstchild.data = document.getelementbyid ('counter').firstchild.data - 1         settimeout ('tick()', 1000)     } else {         document.getelementbyid ('counter').firstchild.data = 'done'     } }  if (document.getelementbyid) onload = function () {     var t = document.createtextnode (counter_start)     var p = document.createelement ('p')     p.appendchild (t)     p.setattribute ('id', 'counter')      var body = document.getelementsbytagname ('body')[0]     var firstchild = body.getelementsbytagname ('*')[0]      body.insertbefore (p, firstchild)     tick() } 

jsfiddle

  1. remove tick()
  2. update counter_start value want
  3. call tick on click of button.

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -