Skip to main content
17 events
when toggle format what by license comment
Dec 24, 2019 at 16:11 review Suggested edits
Dec 24, 2019 at 16:51
Jul 22, 2019 at 18:29 comment added stackers this does scroll if you set "scroll-behavior: smooth;" on the html element
Oct 30, 2017 at 16:16 review Suggested edits
Oct 30, 2017 at 17:25
Dec 6, 2016 at 9:33 comment added Markus Zeller @German Oh, you're right. Hash is of course independent of the location object.
Dec 5, 2016 at 12:46 comment added Gherman @MarkusZeller, why shouldn't the parameter be called hash? It doesn't collide with location, does it?
Feb 2, 2016 at 10:32 comment added Markus Zeller You should not use scrollTo, because it is already used by the global window object. Also the parameter should not be named hash, because location.hash is defined, too. You may use this code: function scrollToHash(hashName) { location.hash = "#" + hashName; }
Dec 27, 2015 at 15:48 comment added Srneczek -one - it doesn't scroll
May 13, 2015 at 17:01 comment added Benny Schmidt @Ryan The question was about how to do it in javascript, not HTML.
Dec 23, 2014 at 15:32 comment added nico gawenda When you set the value, you have to omit the hash sign. "location.hash = hash;" - which also makes it pretty weird to wrap it in a function
Nov 10, 2014 at 17:05 comment added Cristian Vrabie Note that this will only work once. Once the hash is set, the page won't scroll to the same hash unless you change it to a dummy one then set it again.
Sep 12, 2014 at 23:29 comment added Alveoli neat and does it without reloading the page. Thanks!
Aug 20, 2014 at 8:30 comment added chris @Qubex_ yes, I think so
Aug 19, 2014 at 12:22 comment added QUB3X @chrisツ It change the URL adding the "#anchor", right?
Feb 7, 2014 at 22:32 comment added Ryan That doesn't actually scroll though, it just jumps. At that point you might as well just link to the anchor <a href="#anchorName">link</a>
Jul 2, 2010 at 6:38 comment added Juha Syrjälä I tried this and decided to use this. You were also the first and had shortest code.
Jul 2, 2010 at 6:37 vote accept Juha Syrjälä
Jul 2, 2010 at 6:25 history answered Dean Harding CC BY-SA 2.5