# .scrollTop()

## scrollTop ( ) Returns: Integer version added: 1.2.6

Description: Get the current vertical position of the scroll bar for the first element in the set of matched elements or set the vertical position of the scroll bar for every matched element.

The vertical scroll position is the same as the number of pixels that are hidden from view above the scrollable area. If the scroll bar is at the very top, or if the element is not scrollable, this number will be `0`.

## Examples:

#### Example: Get the scrollTop of a paragraph.

    <!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>css demo</title>

      <style>

      p {
        margin: 10px;
        padding: 5px;
        border: 2px solid #666;
      }

      </style>

      <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    </head>
    <body>

    <p>Hello</p><p></p>

    <script>

    var p = $( "p:first" );
    $( "p:last" ).text( "scrollTop:" + p.scrollTop() );

    </script>

    </body>
    </html>

#### Demo:

## scrollTop ( value ) Returns: jQuery version added: 1.2.6

- value
  Type: Number
  An integer indicating the new position to set the scroll bar to.

Description: Set the current vertical position of the scroll bar for each of the set of matched elements.

The vertical scroll position is the same as the number of pixels that are hidden from view above the scrollable area. Setting the `scrollTop` positions the vertical scroll of each matched element.

## Examples:

#### Example: Set the scrollTop of a div.

    <!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>css demo</title>

      <style>

      div.demo {
        background: #ccc none repeat scroll 0 0;
        border: 3px solid #666;
        margin: 5px;
        padding: 5px;
        position: relative;
        width: 200px;
        height: 100px;
        overflow: auto;
      }
      p {
        margin: 10px;
        padding: 5px;
        border: 2px solid #666;
        width: 1000px;
        height: 1000px;
      }

      </style>

      <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    </head>
    <body>

    <div class="demo"><h1>lalala</h1><p>Hello</p></div>

    <script>

    $( "div.demo" ).scrollTop( 300 );

    </script>

    </body>
    </html>

#### Demo: