JSFiddle - React, Tailwind, and code Playground

by Johnny Walker

HTML

<div class="long">Scroll down</div>
<p>
<a href="#" class="clickTop">Click to top</a>
</p>

CSS

.long {
  height: 1000px;
}

JavaScript

$('.clickTop').on('click', function(e){
	e.preventDefault();
  
 if ($('html').scrollTop()) {
        $('html').animate({ scrollTop: 0 }, function() {
            console.log('html scroll');

        });
        return;
    }

    if ($('body').scrollTop()) {
        $('body').animate({ scrollTop: 0 }, function() {
            console.log('body scroll');
        });
        return;
    }
  
});