How to redirect to another page in JavaScript on button click?

To redirect to another page in JavaScript on button click, assign the URL to location.href inside the click handler.

For example, if this is your button:

<button id="my-button">Click to Redirect</button>

Then you can make it redirect on click with this JavaScript:

document.getElementById('my-button').addEventListener('click', () => {
  location.href = 'https://whaa.dev';
});