.scrollLeft()
methodThe .scrollLeft()
method in jQuery is used to get/set the horizontal position position of the scroll bar for the matched element.
.scrollLeft()
method Syntax.scrollLeft() .scrollLeft(value)
.scrollLeft()
get the horizontal position of the scroll bar for the first matched element. If the element is not scrollable, this number will be 0
Get the scrollLeft of the second div.
var div = $("div:eq(1)"); var scrollLeft = div.scrollLeft(); console.log(scrollLeft);
.scrollLeft(value)
Set the horizontal position of the scroll bar for each matched element.
value
is new position to set the scroll bar to.
Set the scrollLeft of a div to 50px.
$('div').scrollLeft(50);