Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
154
rated 0 times [  161] [ 7]  / answers: 1 / hits: 45600  / 12 Years ago, wed, september 5, 2012, 12:00:00

I have a div which located at the bottom of the page:



<div id=myDiv></div>


I want to go to this div after performing of my JS-function. In other words, I want to have my url become myurl#myDiv and to go to my div. But without reloading the page. How this can be done using JavaScript? Unfortunately I have not found a working solution for this issue. I am not using any JS-libraries and frameworks.


More From » html

 Answers
73

Try setting the window's location to that of the ID. The browser will then scroll to that element.



window.location.hash = '#myDiv';

[#83233] Tuesday, September 4, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jameson

Total Points: 534
Total Questions: 103
Total Answers: 102

Location: Lithuania
Member since Fri, Sep 4, 2020
4 Years ago
jameson questions
;