Home >>jQuery Tutorial >jQuery scrollTop() Method
jQuery scrollTop() method in jQuery is an inbuilt method which is used to sets or returns the vertical scrollbar position for the selected elements.
Syntax:Return vertical scrollbar position: | $(selector).scrollTop() |
Set vertical scrollbar position: | $(selector).scrollTop(position) |
Parameter | Description |
---|---|
position | This parameter is used to specifies the vertical scrollbar position |
<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($(".ScrollTop").scrollTop() + " px");
});
});
</script>
</head>
<body>
<div class="ScrollTop" style="border:1px solid black;width:100px;height:150px; padding:4px; overflow:auto">
Phptpoint!! Phptpoint!! Phptpoint!! Phptpoint!! Phptpoint!! Phptpoint!! Phptpoint!! Phptpoint!! Phptpoint!! Phptpoint!! Phptpoint!!</div><br>
<button class="btn1">Click me to Return the vertical position of the scrollbar</button>
</body>
</html>