Jump to Location Within Page

Like this blog? Consider exploring one of our sponsored banner ads...

I know of three very easy ways to jump to a location within a page. They are using the scrollTo() function, the window.location.hash function, and the Prototype scrollTo() function.

This example uses the Javascript scrollTo() function where you simply pass the X,Y pixel coordinates that you want to jump the page to. This example would jump the page to the top:

onclick="self.scrollTo(0,0);"

The second way I have done this is to create a named anchor and use the javascript window.location.hash function to jump to it. So basically create a named anchor called “JUMP2″ or whatever you like and then make it happen like this:

onclick="window.location.hash='JUMP2';"

And for my personal favorite, using Prototype you can jump the page to any html element. So basically give some element an id of “JUMP2″ or whatever you like and then make it happen like this:

onclick="$('JUMP2').scrollTo();

About this entry