Jump to content

jump to the element on a page


skaterdav85

Recommended Posts

You know how you can jump down/up to a particular part of the page if you put the element's id in the url? So by putting the id in the href attribute of an anchor, you can cause the page to jump to that id.

<div id="div1">this is my div</div><a href="#div1">somewhere on the page</a>

Is there a way to control this behavior in JavaScript? I have points on a map and each point knows which ID to jump to, but I don't know how to tell it to jump to a particular ID on the page when clicked. I have already added a click event listener to each point. I just need to make it do the jumping part.

Link to comment
Share on other sites

Make each point an <a> element with the href attribute. Or use can use image maps to make a specific part of an image behave like a link.

Link to comment
Share on other sites

There's the scrollTo() and scrollBy() methods, but they scroll to coordinates, not to elements. If you want to get a "scroll compatible" position of an element, you'll probably have to look at the scroll* properties of the element.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...