javascript - How to make time function update itself? -


when load in browser it'll show time when page loaded, won't update every second. how do this?

var h = date.gethours();   if(h<10) h = "0"+h; var m = date.getminutes(); if(m<10) m = "0"+m; var s = date.getseconds(); if(s<10) s = "0"+s; document.write(h + " : " + m + " : " + s); 

use setinterval:

setinterval(clock, 1000);  function clock() {    var date = new date();    var h = date.gethours();   if(h<10) h = "0"+h;    var m = date.getminutes(); if(m<10) m = "0"+m;    var s = date.getseconds(); if(s<10) s = "0"+s;    document.write(h + " : " + m + " : " + s); } 

although want update html element rather document.write page every second.

http://jsfiddle.net/bqnwj/


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -