Button link | Sololearn: Learn to code for FREE!


Button link

How can I add a link to an HTML button?

12/1/2016 2:09:28 PM

Caleb Jore

5 Answers

New Answer


credits to user: kambiz (@SubScript) i saw it earlier and thought i'd share... Quote: " Just add an onclick event to the button: But you shouldn't really have it inline like that, instead, put it in a JS block and give the button an ID: <button id="myButton" class="float-left submit-button" >Home</button> <script type="text/javascript"> document.getElementById("myButton").onclick = function () { location.href = "www.yoursite.com"; }; </script> "


Thanks guys! I'll try these ideas in my code.


1. option - Create plain anchor (<a>) and style it as a button 2. option - Create button and add onclick event handler which through document location changes the URL (document.location ="http://...")


You have a few options to get a HTML button to act as a hyperlink. The easiest way is to have a form, having a redirect action: <form action="http://www.sololearn.com"> <input type="submit" value="SOLOLEARN" /> </form> Or, you could have a simple link and style it to look like a button using CSS. For more details, check the appearence CSS attribute: http://www.w3schools.com/cssref/css3_pr_appearance.asp


Links in html can be attached to a button in a real simple way by placing a button in place of text between <a> tags like so: <a href='www.sololearn.com'><button>Website</button></a> Using this method will require that whatever you're linking to is actually on the website. This method will not take you to a third party source.