Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Link inside a button not working in Firefox

I have two links inside a button but the links don't seem to work on Firefox.

<button class="btn login">
    <a href="/login"><b>Log In</b></a> 
          | 
<a href="/signup"><b>Sign Up</b></a>
</button>

I tried JavaScript onclick and redirecting - even that is not working.

like image 711
Stacy J Avatar asked Jun 22 '13 17:06

Stacy J


People also ask

Why won't a link open when I click on it Firefox?

Clear the Cache and remove the Cookies for websites that cause problems via the "3-bar" Firefox menu button (Options/Preferences). Start Firefox in Safe Mode to check if one of the extensions ("3-bar" menu button or Tools -> Add-ons -> Extensions) or if hardware acceleration is causing the problem.

Why do my links not work in Firefox?

If you see hyperlinks but they don't work, then it's possible that there is an issue with the web page. The web page may not be compatible with the browser version you're using. In addition, Firefox may not be set as your default browser.

Can you put a link inside a button?

We can create a button that acts as a link by nesting the <button> tag inside the anchor tag. We can specify the address of the link through the href attribute. For example, create an anchor element inside the HTML body. Inside the anchor element, write the href attribute and specify the URL https://www.youtube.com .

How do I make a hyperlink work as a button?

You can just use the <a> tag with a button inside :). And it will load the href into the same page.


2 Answers

This doesn't work because it is not allowed by HTML5:

Content model: Phrasing content, but there must be no interactive content descendant.

Interactive content means any of the following elements:

a audio (if the controls attribute is present) button details embed iframe img (if the usemap attribute is present) input (if the type attribute is not in the hidden state) keygen label menu (if the type attribute is in the toolbar state) object (if the usemap attribute is present) select textarea video (if the controls attribute is present)

If it does work in some browsers it's just because they're trying to play nice with malformed markup and provide some sort of meaningful result.

In other words: rewrite your HTML, it's a mess. If you want the links to look like they're in a button, put them in a div element and style that to look like one, instead of abusing semantically wrong elements for it.

like image 65
Niels Keurentjes Avatar answered Oct 04 '22 17:10

Niels Keurentjes


<a> is not allowed inside <button>

Phrasing content, but there must be no interactive content descendant.

<a> is interactive content (regardless of whether it has an href apparently, but yours do). Thus you can't depend on having the links as children of the button and what Firefox is doing is correct. Use another element to contain the <a>s

like image 45
Explosion Pills Avatar answered Oct 04 '22 16:10

Explosion Pills