Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript window.location id

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 ?

like image 1000
user1128331 Avatar asked Mar 24 '23 07:03

user1128331


1 Answers

Scroll to the element:

document.querySelector('#test').scrollIntoView();
like image 154
Blender Avatar answered Mar 31 '23 20:03

Blender