We all know that scroll to top with named anchors via HTML is possible but is it possible to scroll to the top when another HTML element is clicked that is not surrounded by tags? For instance, a DIV?
EDIT: Apologies all, I did not see this was a duplicate question. I did a search and didn't find anything.
You could listen for a click event on your div and use scrollTo when it is clicked.
window.scrollTo( x-coord, y-coord ):
Scrolls to a particular set of coordinates in the document.
x-coord is the pixel along the horizontal axis of the document that
you want displayed in the upper left. y-coord is the pixel along the
vertical axis of the document that you want displayed in the upper
left.
this should work for any block element:
good luck ...
You could listen for a
click
event on yourdiv
and usescrollTo
when it is clicked.You can achieve this by using JavaScript:
or with jQuery:
Yes, you might want to do it with Javascript by using
and assigning it to the div
You can insert every kind of html tag into the bracket's
if you want to go for jquery solution than you can use
html will be
full article : Scroll to the top of a webpage with jQuery