jQuery CSS Operation - scrollLeft() Method

Example

Set the horizontal offset of the scrollbar in the <div> element:

$(".btn1").click(function(){
  $("div").scrollLeft(100);
});

Try it yourself

Definition and Usage

The scrollLeft() method returns or sets the horizontal scrollbar position of the matching elements.

The horizontal position of the scrollbar refers to the number of pixels scrolled from the left. When the scrollbar is at the far left, the position is 0.

Returns horizontal scrollbar position

Returns the horizontal scrollbar position of the first matching element.

Syntax

$(selector).scrollLeft()

Try it yourself

Set horizontal scrollbar position

Sets the horizontal scrollbar position of all matching elements.

Syntax

$(selector).scrollLeft(position)
Parameters Description
position Optional. Specifies the new position in pixels.

Try it yourself