how to reset scroll position in a div using javascript

Anand Jha picture Anand Jha · Oct 21, 2013 · Viewed 59.4k times · Source

I am working on a mobile hybrid application.

In my html page, I have 3 tabs. When clicking a tab, the content of the scrollable div gets changed. My problem is when I scroll down the content of div (view) and click another tab, the content disappears (but the content is there). Please help me so I can reset the div scroll position when clicking any tab.

Please give me suggestions only with JavaScript or CSS, not with JQuery as I am not using the JQuery library.

Answer

Shadow picture Shadow · Oct 21, 2013

Without seeing code, i can just guess. If you want to reset the scroll position you can simply use

window.scrollTo(0,0); 

add this code to your each tab click functions so that when ever you click any tab, it resets to top.

If you have any specific div that has overflow property

var myDiv = document.getElementById('specificDiv');
myDiv.scrollTop = 0;