jQuery scrollTop()Method
Examples
Return the vertical scrollbar position of a <div> element:
$("button").click(function(){
alert($("div").scrollTop());
});
Try it yourself »
Definition and Usage
The scrollTop() method sets or returns the vertical scrollbar position of the selected elements.
Tip:When the scrollbar is at the top, the position is 0.
When used to return the position:
This method returns the vertical position of the scrollbar of the first matched element.
When used to set the position:
This method sets the vertical position of the scrollbar for all matched elements.
Syntax
Return the vertical scrollbar position:
$(selector).scrollTop()
Set the vertical scrollbar position:
$(selector).scrollTop(position)
| Parameter | Description |
|---|---|
| position | Specifies the vertical scrollbar position in pixels. |
More Examples
Set the vertical scrollbar position
How to set the vertical scrollbar position for an element.
Other Extensions
jQuery HTML/CSS Methods