When calling an alert for document.body.scrollHeight at 5 second intervals, the alert returns the initial scrollHeight of the document, but does not change even when the scroll height of the page has clearly changed. Is there any way to make it return the actual scroll height of the page, and not just the initial value?
The code/pseudocode
<script>
setInterval(function() {
alert(document.body.scrollHeight);
}, 5000);
function extendHeight() {
document.getElementById('box').style.height = 1000;
}
</script>
<body>
<div id='box' style='height: 500px;'>
<button onClick="extendHeight();">Change Height</button>
</div>
</body>
Even after clicking button, the alert returns 500 px.
The problem is you should assign
'1000px'todocument.getElementById('box').style.heightnot1000:Fiddle: http://jsfiddle.net/kzLEr/