Jquery scroll to top

Jquery scroll to top

Jquery scroll to top

I have a button a user presses and it shows a hidden div using jQuery.

My question is, how do I scroll to the top of the page using a jQuery command in that function? It is desirable even if the scroll bar instantly jumps to the top. I’m not looking for a smooth scrolling.

Jquery scroll to top
Jquery scroll to top
  • Add library Jquery:

<script src=”../js/jquery.js”></script>

  • Code Html

<p><button id=”scroll”>Scroll</button></p>

<div id=”test”>Bottom</div>

  • Stylesheet:

#test {
width: 100px;
height: 100px;
position: relative;
top: 1000px;
background: green;

and Jquery scroll to top:

All of these suggestions work great for various situations. For those who find this page through a search, one can also give this a try. JQuery, no plug-in, scroll to element.


$(‘#scroll’).click(function() {
scrollTop: $(‘#test’).css(‘top’)
}, 800, function() {

$(‘html, body’).animate({
scrollTop: 0
}, 800);



Jquery scroll to top

Demo (click result) :

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *