Home >>jQuery Tutorial >jQuery scrollLeft() Method

jQuery scrollLeft() Method

jQuery scrollLeft() Method

jQuery scrollLeft() method in jQuery is used to sets or returns the horizontal scrollbar position the selected elements.

Syntax:
Return horizontal scrollbar position: $(selector).scrollLeft()
Set horizontal scrollbar position: $(selector).scrollLeft(position)

Parameter Values

Parameter Description
position It is used to specifies the horizontal scrollbar position in pixels
Here is an Example of jQuery scrollLeft() Method:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".btn1").click(function(){
alert($(".ScrollLeft").scrollLeft() + " px");
});
});
</script>
</head>
<body>
<div class="ScrollLeft" style="border:1px solid black;width:120px;padding:4px; height:150px;overflow:auto">
Phptpoint!! Phptpoint!! Phptpoint!! Phptpoint!! Phptpoint!! Phptpoint!! Phptpoint!! Phptpoint!! Phptpoint!! Phptpoint!! Phptpoint!! 
</div><br>
<button class="btn1">Click me to return the horizontal position of the scrollbar</button>
</body>
</html>

Output:
Phptpoint!! Phptpoint!! Phptpoint!! Phptpoint!! Phptpoint!! Phptpoint!! Phptpoint!! Phptpoint!! Phptpoint!! Phptpoint!! Phptpoint!!


No Sidebar ads