0

I'm writing a code in HTML and it has 2 buttons, say a and b. I want to pass something in my URL that will trigger the button. I know how we do it for div.

<div class="a">
  <a name="a" /> This is Div A
</div>
<div class="b">
  <a name="b" /> This is Div B
</div>

and I can directly pass myURL.com#a/myURL.com/#b, to go to that div. But I want to know if I can do it using buttons.

Thanks

Granny
  • 783
  • 11
  • 22
user3872094
  • 3,269
  • 8
  • 33
  • 71
  • so you want buttons to go to the `divs` ? or what exactly. Possible duplicate of https://stackoverflow.com/questions/3163615/how-to-scroll-html-page-to-given-anchor – Edwin Jan 18 '18 at 12:28

3 Answers3

1

Yes you can do it with some javascript like:

<button onclick="window.location='#a';">Go to Div A</button>
Bruno Sousa
  • 480
  • 3
  • 12
0

If you want either button A OR button B to be visable you can use this:

CSS

.button {
    display: none;
    }
.button:target {
    display: block
    }

HTML

<!-- link in the same page -->
<a href="#A">go to button 1</a><br>
<a href="#B">go to button 2</a><br>

<!-- link from external page -->
<a href="your_url.com/#A">go to button A</a><br>
<a href="your_url.com/#B">go to button B</a><br>

<!-- buttons will only be visable when linked to -->
<a class="button" id="A"><input type="button" value="button A"></a>
<a class="button" id="B"><input type="button" value="button B"></a>

If you just want to jump to the button you answered your own question. Just wrap the <div id="A"> around the button.

AA-T
  • 83
  • 7
-1

First add the id attribute to the div. Eg; <div class="b" id="part-b"> Then just link to mypage.html#part-b, eg; <a href="mypage.html#part-b>Go to part b</a>

giorgio
  • 10,111
  • 2
  • 28
  • 41