Question

I want to make the browser to scroll the div's id

<div id="test">
   lol
</div> 

So I use this code

window.location = "#test";

but my url now is like this

http://locahost/index.html#test

Is it possible to delete "#test" but go to that ?

Was it helpful?

Solution

Scroll to the element:

document.querySelector('#test').scrollIntoView();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top