0

I am trying to redirect to a link when the button is clicked, but it is not working, please need a working code, please.

function myFunction() {
  document.getElementById("mycom").location.href = "http://mywebsite.com/home.html"";    
}

<button type="button" onclick="myFunction()">Try it</button>
James Hooper
  • 756
  • 8
  • 18
  • 2
    Well, `""` isn't helping. And it should probably be `window.location.href`. All of which you could have solved by debugging your code. – Andy May 02 '22 at 16:43

1 Answers1

0

To redirect change your function to the following:

function myFunction() {
   window.location = 'http://mywebsite.com/home.html'
}
Sean Lawton
  • 814
  • 5
  • 15