
On Button Click ReDirect to Another Page
Sometimes You may want to use a button to link to another page or website.
Add an
onclick
event to the button.
<button onclick="location.href = 'example.com';" id="myButton"> Button </button>
<button id="myButton">Home</button>
document.getElementById("myButton").onclick = function () { location.href = "example.com"; };
Name A function to HTML Element
HTML Button onClick Redirect
<button name="redirect" onClick="redirect()">
function redirect() { let url = "http://example.com"; window.location(url); }
You could change the action attribute of the form on Click the button
myFun(){ $('form').attr('action','new path'); }