Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12141

How can we enable scrolling up the page upon clicking a button in HTML simply?

$
0
0

The issue pertains to the length of the code used for scrolling up the page upon button click.

<div class="back-to-top"><a href="#top">Back to Top</a></div><hr></div><script>  document.getElementById('back-to-top').addEventListener('click', () => {     window.scrollTo({ top: 0, behavior: 'smooth' });  });</script>

I found the current code for scrolling up the page upon button click to be somewhat lengthy. Any suggestions for a more concise implementation?


Viewing all articles
Browse latest Browse all 12141

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>