Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap Button Hyperlink

I do not want to use <a> element to convert a button into a hyperlink.

I have the following buttons:

<button class="btn btn-success"> First button</button>
<button class="btn btn-success"> Second button</button>

How do I specify a hyperlink (without using <a>) and browse to a page when I click on the buttons

like image 533
CuriousDev Avatar asked Jul 21 '15 03:07

CuriousDev


2 Answers

You can use JavaScript for your solution. window.location.href sets the URL for the button.

<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<button class="btn btn-success" onclick="window.location.href='http://cdnjs.com/libraries/twitter-bootstrap'">First button</button>
like image 128
m4n0 Avatar answered Oct 16 '22 16:10

m4n0


can we know why you want the button to be button not link tag? would you consider this code helpful to achieve what you want ?

<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
    <a href="http://www.google.com" role="button" class="btn btn-success btn-large">Google Now</a>
like image 40
codder Avatar answered Oct 16 '22 18:10

codder