-2

I have a button, when you click the button it will take you to one of my sub-sites.

The button is a child element of a a tag. Is there a better way?

<a target='_blank' href='example.com/sub-site.html'>
<button name='link' style="cursor:pointer"  class='example-style' value='example.com/sub-site'
title='Example Title>Example</button></a>

If possible, I'll prefer not to use the form tag.

Thanks!

Banana.html
  • 35
  • 14

3 Answers3

0

Use JavaScript to redirect. An example is shown here:

<button id="button1">Example</button>
<script>
document.getElementById('button1').onclick = function() {
    window.location.href = "example.com/sub-site";
}
</script>
sportzpikachu
  • 831
  • 5
  • 18
0

You can add the href directly inside the <button> tag:

<button onclick="window.location.href = 'example.com/sub-site.html';">Example</button>

I hope this helps!

ADIGEN
  • 31
  • 2
  • 5
0

if your question is what is better "a href..." or "button...: I will tell you that for me it is the "a href" because the redirection is explicit.