Bootstrap Button Hyperlink

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

I have the following buttons:

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

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

+7
javascript css twitter-bootstrap
source share
2 answers

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

 <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> 
+5
source share

can we know why you want the button to be not a link tag? Could you find this code useful for achieving 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> 
+3
source share

All Articles