0

I need to add a link into these buttons:

<div class="buttons"> <button class="action bluebtn"><span class="label">CREATE NEW ACCOUNT</span></button> <button class="action redbtn"><span class="label">EDIT ACCOUNT</span></button> <button class="action greenbtn"><span class="label">IMPORT EDI TEXT FILES</span></button> <button class="action"><span class="label">LOG OUT</span></button> </div> 

Can somebody help me?

6
  • What do you mean by you need to add a link into the buttons... a link to what? Commented Dec 21, 2012 at 12:03
  • A hyper link to another page. Commented Dec 21, 2012 at 12:05
  • Try the solution in this SO Answer stackoverflow.com/a/2906586/96505 Commented Dec 21, 2012 at 12:07
  • Is there a specific reason you're not just using an href element and styling it to look like a button with CSS? Commented Dec 21, 2012 at 12:09
  • Have a look at this sample Commented Dec 21, 2012 at 12:19

4 Answers 4

4

You have several options here, depending on whether you can change the HTML:

If you can change the HTML make the buttons into a regular <a href="http://www....">link</a> or you can add an onclick event:

<button class="action bluebtn" onclick="javascript:document.location='some-url'"> <span class="label">CREATE NEW ACCOUNT</span> </button> 

If you can't change the HTML, grab the buttons using something like jQuery and add the onclick event there:

$("button.bluebtn").click(function(){ document.location = 'some-url'; return false; }); 

But I do recommend changing the buttons into regular links if you can. Having <button> elements acting as links makes no sense...

Sign up to request clarification or add additional context in comments.

2 Comments

Making them anchors and styling them like buttons is beat imo
@rlemon, you are right, I was still busy trying to add that part ;)
3

If you really need to use the <button> tag you can add the link with Javascript:

<button onclick="location.href='url_address'">Your HTML content</button> 

I think it would be more consistent thought to use <a> tags instead of <button>'s and then style them with CSS to look like the buttons. This way you rely on the default behavior of your markup and avoid having to use Javascript.

Comments

0
<input type="button" value="click for google" onClick="window.location='http://w­ ww.google.com' "> 

or you may use

<button onclick="document.location.href='link';­ return false;">Link Text</button> 

Comments

-2

I think you just wrap the button with a href element like the following:

<div class="buttons"> <a href="your link here"><button class="action bluebtn"><span class="label">CREATE NEW ACCOUNT</span></button></a> </div> 

and do same for rest of the buttons. Wrap them with "a href" tag.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.