$('#backToTop').on('click', function () {
$('html, body').animate({ scrollTop: 0 }, 'fast')
})
The below has a fallback which doesn't smooth scroll to the top if the behaviour
property is not supported.
const scrollToTop = () => {
try {
window.scrollTo({
top: 0,
left: 0,
behavior: 'smooth',
})
} catch (error) {
window.scrollTo(0, 0)
}
}