I want to scroll to the top of the page when I click on a button. How should I achieve this?
Asked
Active
Viewed 65 times
-2
-
Possible duplicate of [Scroll to the top of the page using JavaScript/jQuery?](https://stackoverflow.com/questions/1144805/scroll-to-the-top-of-the-page-using-javascript-jquery) – SomeBruh Sep 21 '17 at 09:03
2 Answers
3
You can call this inside the button click event
goTop(){
window.scrollTo(0, 0);
}

Sajeetharan
- 216,225
- 63
- 350
- 396
-
It is not working. I have a frame with scroll bar in the right of the page. – Nelul Sep 21 '17 at 09:16
-
1This was the answer. Somewhere in OnClick function I had to put this: this.elementRef.nativeElement.querySelector('#trip-request-step-' + index ).scrollIntoView(); Where #trip-request-step is the id element from the page where I want to navigate. – Nelul Sep 21 '17 at 10:17
0
This was the answer. Somewhere in OnClick function I had to put this:
this.elementRef.nativeElement.querySelector('#trip-request-step-' + index ).scrollIntoView();
Where #trip-request-step is the id element from the page where I want to navigate.

Nelul
- 115
- 1
- 8