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

Winapi c++: DialogBox hangs when breaking a loop -

vb.net - Font adding using PDFsharp -

javascript - jQuery iScroll clickable list elements while retaining scroll? -