Example 1: jquery get document scrolltop var top = ( $ ( window ) . scrollTop ( ) || $ ( "body" ) . scrollTop ( ) ) ; Example 2: js scrollto element. scrollTo ( x , y ) ; window. scrollTo ( x , y ) ; element .scrollTo ( { top : 100 , left : 100 , behavior : 'smooth' } ) ; Example 3: jquery keep scroll position var scroll = $ ( window ) . scrollTop ( ) ; // yada $ ( "html" ) . scrollTop ( scroll ) ; Example 4: html scroll div to top var myDiv = document. getElementById ( 'containerDiv' ) ; myDiv.innerHTML = variableLongText ; myDiv.scrollTop = 0 ; Example 5: javascript scroll privent // left: 37 , up: 38 , right: 39 , down: 40 , // spacebar: 32 , pageup: 33 , pagedown: 34 , end: 35 , home: 36 var keys = { 37 : 1 , 38 : 1 , 39 : 1 , 40 : 1 } ; function preventDefault ( e ) { e. preventDefault ( ) ; } function preventDefaultForScrollKeys ( e ) { if ( keys [ e .keyCode ] ) { preventDefault ( e ) ; return false