Warrior Forum - The #1 Digital Marketing Forum & Marketplace

Warrior Forum - The #1 Digital Marketing Forum & Marketplace (https://www.warriorforum.com/)
-   Programming (https://www.warriorforum.com/programming/)
-   -   Combining the a href + button tag? (https://www.warriorforum.com/programming/1358763-combining-href-button-tag.html)

dansbanners 11th August 2018 06:11 PM

Combining the a href + button tag?
 
Would it cause any problems in the website or any browers?

<a href="whatever.html'><button>text in here</button></a>

Is there a better alternative? Thanks.

Hasib Mahmud 12th August 2018 05:07 AM

RE: Combining the a href + button tag?
 
Thanks, Brother

dansbanners 12th August 2018 09:37 AM

Re: Combining the a href + button tag?
 
Quote:

Originally Posted by Hasib Mahmud (Post 11409906)
Thanks, Brother

Glad you found it helpful. However, I'm wondering if it'll cause any problems or if there's a better way to do it, etc?

Michael D Price 14th August 2018 12:07 AM

Re: Combining the a href + button tag?
 
To be honest,
I am a big fan of bootstrap.
Using bootstrap you can just apply a button style to an anchor link and get the desired visual effect of a button.

To do this without using booststrap, you should remove the button code, and just use css to style the link to look like a button.

For a more advanced method, use javascript for the linking.
https://codepen.io/svinkle/pen/FHGBh

srdjanm 14th August 2018 05:27 AM

RE: Combining the a href + button tag?
 
No, it isn't valid HTML5 according to the HTML5 Spec Document from W3C:

In other words, you can nest any elements inside an <a> except the following:
Code:

<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 you are trying to have a button that links to somewhere, wrap that button inside a <form> tag as such:

Code:

<form style="display: inline" action="http://example.com/" method="get">
  <button>Visit Website</button>
</form>

However, if your <button> tag is styled using CSS and doesn't look like the system's widget... Do yourself a favor, create a new class for your <a> tag and style it the same way.

Jari Niemi 15th August 2018 04:05 AM

Re: Combining the a href + button tag?
 
Quote:

Originally Posted by dansbanners (Post 11409779)
Would it cause any problems in the website or any browers?

<a href="whatever.html'><button>text in here</button></a>

Is there a better alternative? Thanks.

Button sample:

https://superdevresources.com/super-...st-button-css/

ANJANBD 16th August 2018 06:19 PM

Re: Combining the a href + button tag?
 
<a class="button" href="#">This is Button</a>
<style>
.button{
padding:5px;
background:black;
color:white;
border-radius:5px;
}
a{
text-decoration:none;
}
</style>

swati tiwari 28th September 2018 04:30 AM

RE: Combining the a href + button tag?
 
There is no alternate tag for <a> in HTML. But you can create it's alternative using JavaScript.

It is way less efficient than <a> tag. But if you still want to do it, follow me.

HTML:

<body>
<p class="para">
<span id="redirect">
</span>
</p>

CSS:

.para {
font-family: sans-serif;
color: #F00;
font-size: 127%;
text-decoration: none;
}
#redirect {
font-family: inherit;
color: #0F0;
text-decoration: underline;
}
JavaScript:

document.getElementById("redirect").onclick(redire ct());
function redirect() {
window.location.href="whatever.html";
//May load a cached page
};

dansbanners 30th September 2018 09:35 AM

Re: Combining the a href + button tag?
 
Quote:

Originally Posted by swati tiwari (Post 11430981)
There is no alternate tag for <a> in HTML. But you can create it's alternative using JavaScript.

It is way less efficient than <a> tag. But if you still want to do it, follow me.

HTML:

<body>
<p class="para">
<span id="redirect">
</span>
</p>

CSS:

.para {
font-family: sans-serif;
color: #F00;
font-size: 127%;
text-decoration: none;
}
#redirect {
font-family: inherit;
color: #0F0;
text-decoration: underline;
}
JavaScript:

document.getElementById("redirect").onclick(redire ct());
function redirect() {
window.location.href="whatever.html";
//May load a cached page
};

Yes. That's another way to do it. I settled on <a class="button"...> and CSS. Thanks.

Marek Anral 6th October 2018 01:18 PM

RE: Combining the a href + button tag?
 
Add "display:block;" to "button" class, then whole button will be clickable.

shraddha patel 4th April 2019 10:58 PM

RE: Combining the a href + button tag?
 
<input type="button" class="btn btn-info" value="Input Button" onclick=" relocate_home()">

<script>
function relocate_home()
{
location.href = "www.yoursite.com";
}
</script>


All times are GMT -6. The time now is 02:34 AM.