imhere imhere - 12 days ago 5
HTML Question

Scroll back to the top of div

<div id="containerDiv"> </div>


#container {
position:absolute;
top:0px;
width:400px;
height:100%;
padding:5px;
font-size:.875em;
overflow-y: scroll;
}


document.getElementById("containerDiv").innerHTML = variableLongText;


How to reset the scroll position back to top of container div the next time?

Answer
var myDiv = document.getElementById('containerDiv');
myDiv.innerHTML = variableLongText;
myDiv.scrollTop = 0;

See the scrollTop attribute.

Comments