How can I redirect on button click in javascript?

Viewed 12

I am trying to send users to a different part of my app on a button click and I tried using

const button = document.getElementById('button');
button.onclick = window.location.replace('example.html');

and also

const button = document.getElementById('button');
button.onclick(window.location.replace('example.html'));

but both of these just redirected immediately on loading.

0 Answers
Related