jQuery Tutorial

jQuery scrollTop() Method With Syntax and Example

What is scrollTop method in jQuery?

For the selected components, The scrollTop() method sets or returns the vertical scrollbar position

The position is 0 when the scrollbar is at the top.

Syntax of scrollTop method in jQuery

  • Return vertical scrollbar position:

$(selector).scrollTop()

  • Set vertical scrollbar position:

$(selector).scrollTop(position)

Example of jQuery scrollTop method

For a

element, get the vertical scrollbar position:

 

$("button").click(function(){
  alert($("div").scrollTop());
});
Did you find this article helpful?