How to Scroll to the top of the page using JavaScript?

0 votes
How do I scroll to the top of the page using a JavaScript? It is desirable even if the scrollbar instantly jumps to the top. I'm not looking for a smooth scrolling.

Thank You!!
Apr 2 in Java-Script by kartik
• 11,290 points
15 views

1 answer to this question.

0 votes

Hii @kartik,

Using javascript

<script>

  $("a[href='#top']").click(function() {
     $("html, body").animate({ scrollTop: 0 }, "slow");
     return false;
  });
</script>

However you don't need javascript  to do this. A standard HTML tag will suffice..

<a href="#top">go top</a>

Thank You!!

answered Apr 2 by Niroj
• 22,790 points

Related Questions In Java-Script

0 votes
1 answer

How to get the browser to navigate to URL in JavaScript?

Hii, This works in all browsers: window.location.href = '...'; If ...READ MORE

answered 5 days ago in Java-Script by Niroj
• 22,790 points
21 views
0 votes
1 answer

How to implement useEffect() so the list on the front page updates only when a name change has been detected?

Hello @kartik, Instead of passing the entire object ...READ MORE

answered 1 day ago in Java-Script by Niroj
• 22,790 points
14 views
+1 vote
1 answer

How can we send message multiple time to a specific person or group in whatsapp using loop?

Hii @kartik,  This is simple task to send single ...READ MORE

answered Feb 28 in Java-Script by Niroj
• 22,790 points
230 views
0 votes
1 answer

How to clone a JavaScript object?

Hello, You can clone an object and remove ...READ MORE

answered Apr 2 in Java-Script by Niroj
• 22,790 points
15 views
0 votes
1 answer

Why it is necessary to refresh CSRF token per form request?

Hello, Generating a new CSRF token for each ...READ MORE

answered Mar 19 in Laravel by Niroj
• 22,790 points
186 views
0 votes
1 answer

What is meant by passing the variable by value and reference in PHP?

Hello, When the variable is passed as value ...READ MORE

answered Mar 27 in PHP by Niroj
• 22,790 points
36 views
0 votes
1 answer

Connection with MySQL server using PHP. How can we do that?

Hey @kartik, You have to provide MySQL hostname, ...READ MORE

answered Mar 27 in PHP by Niroj
• 22,790 points
41 views
0 votes
1 answer

How to retrieve or obtain data from the MySQL database using PHP?

Hello kartik,  Actually there are many functions that  ...READ MORE

answered Mar 27 in PHP by Niroj
• 22,790 points
33 views
0 votes
1 answer

How to get the directory of the currently running file?

Hello @kartik, This should do it: import ( ...READ MORE

answered May 5 in Java-Script by Niroj
• 22,790 points
24 views
0 votes
1 answer

How to use Redirect in the new react-router-dom of Reactjs?

Hello, To navigate to another component you can ...READ MORE

answered May 18 in Java-Script by Niroj
• 22,790 points
28 views