Let's say I'm currently at "mehere.com" and if I click a button from there, I want the page to redirect to "gothere.com" then scroll down to the section that has id="rightHere". So I tried 2 different ways and both redirects to the page successfully, but does not scroll down to section. Page loads then stays at top of the screen.
// #1 Method
<button onclick="Redirect()">Click</button>
function Redirect() {
window.location.href = "https://www.gothere.com#rightHere";
}
// #2 Method
<button><a href="https://www.gothere.com#rightHere">Click</a></button>
Is there a alternative way to get screen to scroll down to specific specific section of the page with JavaScript?
Unfortunately there is no alternative way. We need the id to scroll to a specific part of the page.
The most ideal method for solving the problem;
<a href="https://www.gothere.com#rightHere">Click</a>
Also, you don't need to add a button tag, this is more ideal.