Hi how do i display the javascript results in a div. the code is :
<script type='text/javascript'>
COUNTER_START = 40
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()
}
</script>
i want it to display the coundown counter in this div
<div id="counter"></div>
Thank you 😀
You can use
innerHTMLfor that:You can shorten that script a fair bit: Live Example | Source
I wasn’t sure what the stuff with the paragraph element was, so I didn’t include that. If it was meant to add the
counterelement at the beginning of thebody(as ap, not adiv), then just changeto
Doesn’t even need the
id. Live Example | Source