Home  >  Q&A  >  body text

How to create buttons in HTML and JavaScript to redirect pages to different pages

<p>I'm creating a website using VS code and I want to create a button that when clicked will redirect to another page on the website. </p> <p>I want to jump to a new page by clicking the "MENU" button. I've created a new file for the page I want to redirect, just not sure how to get "MENU" to act as a button and take me there. I'm using JavaScript and HTML/CSS in VS code. </p> <p>So I want the button to take me to MENU.js</p> <p>I tried using HTML to create a button but it only works if I link to the URL. I also tried the following. </p> <p><br /></p> <pre>MENU</pre> <p><br /></p> <p>But it doesn't seem to work. </p>
P粉523625080P粉523625080407 days ago437

reply all(1)I'll reply

  • P粉278379495

    P粉2783794952023-08-11 11:05:42

    Why not just use link tags <a> instead of button tags? Or for buttons use the onclick attribute:

    1. <a href="http://www.stackoverflow.com">content</a>
    2. <button type="button" onclick="location.href='http://www.stackoverflow.com'">Content</button>

    reply
    0
  • Cancelreply