If your looking for the fastest way just to scroll to top using native Javascript then use this
1 2 3 4 5 |
<script> window.scrollTo(0,0); </script> |
To scroll to the top of the browser use this code (good for mobile)
1 2 3 |
$('html, body').animate({ scrollTop: 0 }, 'fast'); |
Another version here
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("div").scrollTop(0); }); }); </script> <div style="border:2px solid black;width:100px;height:150px;overflow:auto"> This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. </div><br> <button>Set vertical scrollbar position to top</button> |