1

Hello so I am a beginner in javascript and html and I would like to know if it is possible to go to a specific location on a web page when pressing a button (without reloading the page) and I have no idea of how to do it.

Thank you.

tom3800
  • 99
  • 1
  • 3
  • 8
  • Just add an id for each section in the webpage. Create hyperlinks with href=#id-of-the-section. So when you click on the hyperlink it will scroll to the particular section/element whose is mentioned – Sudharsan Selvaraj Jun 08 '16 at 15:11
  • Do you want to click on a button and go to a link on the same page or a different page in the same site? – j08691 Jun 08 '16 at 15:31
  • the same page if it is possible – tom3800 Jun 08 '16 at 15:47

3 Answers3

7

The only thing that is coming to mind is a link like;

<a href="#yourContentIdHere">name you want to appear as the link here</a>


<div id="yourContentIdHere">
your awesome content
</div>
johara
  • 111
  • 7
4

You can use hyperlinks to do that.

Element target

<div id="element_target">Content</div>

Link to target

<a id="link" href="#element_target">Go to content</a>

To enable Smooth Scrolling, add this to your CSS file

html {  
      scroll-behavior: smooth;  
}
El_Happy
  • 56
  • 4
2

You can also use this code if you ever going to use javascript.

For example when you don't want to put a link but a button like <input type="button></input>", just add <input type="button" onclick="location.href='your desired url'"></input>.