<a href="#">Scroll to Selected Position</a>
Above code worked for me. I tried with onclick="window.scrollTo(0, 0);"
but this does not worked for me, all I needed was href="#"
and no onclick. We might also notice that #
will be getting appended in url
.
Old non-working code has href="javascript:scroll(0,0)"
which had an issue in doing scroll to top in angular/iframe component.
Above code does not worked in Firefox.
Final Solution:
function scrollToSelectedPosition() {
var sectionToJump = document.getElementById('section-to-jump');
$(sectionToJump).scrollIntoView();
}
and
<a onclick="scrollToSelectedPosition()">Scroll to Selected Position</a>
This worked in FireFox, Chrome, Safari and IE.