<script>
window.onload= function(){
var a = document.getElementById('a');
var b = document.getElementById('ct');
setInterval('b.innerHTML = a.duration',1000);
};
</script>
//Second script
<script>
var a = document.getElementById('a');
var b = document.getElementById('ct');
window.onload= function(){
setInterval('b.innerHTML = a.duration',1000);
};
</script>
Why the first script is not working?.
Chrome:
Uncaught ReferenceError: b is not defined
My guess would be: because you use
varonaandbin the first script. This makes the variables local ones inwindow.onload(instead of global), and the code insetIntervalcannot access them.Remove the
varand it should work.