Button link | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Button link

How can I add a link to an HTML button?

1st Dec 2016, 2:09 PM
Caleb Jore
Caleb Jore - avatar
5 Answers
+ 4
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> "
1st Dec 2016, 2:18 PM
Burey
Burey - avatar
+ 4
Thanks guys! I'll try these ideas in my code.
1st Dec 2016, 3:55 PM
Caleb Jore
Caleb Jore - avatar
+ 1
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://...")
1st Dec 2016, 2:16 PM
Ondřej Doněk
Ondřej Doněk - avatar
0
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
1st Dec 2016, 2:14 PM
David Barzi
David Barzi - avatar
0
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.
1st Dec 2016, 2:49 PM
Lux
Lux - avatar