How do i make it so that whenever i press "esc" it scrolls to the top? I have tried to use
<a name="top"></a>
<p>some text here.../p>
<a href="#top" id="backtotop">hi</a>
<script>
var input = document.getElementById("body");
input.addEventListener("keyup", function(event) {
if (event.keyCode === 27) {
event.preventDefault();
document.getElementById("backtotop").click();
}
});
</script>
but it doesn't work. If anyone could help me fix my code, that would be great! :)