Easy Tutorial
❮ Event Select Html Detach ❯

jQuery scrollTop() Method

jQuery HTML/CSS Methods

Example

Return the vertical scrollbar position of a <div> element:

$("button").click(function(){
    alert($("div").scrollTop());
});

Definition and Usage

The scrollTop() method sets or returns the vertical scrollbar position for the selected elements.

Tip: When the scrollbar is at the very top, the position is 0.

When used to return the position: This method returns the vertical position of the scrollbar for 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:

Set the vertical scrollbar position:

Parameter Description
position Specifies the vertical scrollbar position in pixels.

More Examples

Set Vertical Scrollbar Position


jQuery HTML/CSS Methods

❮ Event Select Html Detach ❯