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.
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.
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>
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;
}
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>
.