views:

1511

answers:

2

I have an HTML page that scrolls up and down (not a lot, but it does scroll). I'd like to set the scroll position in the page after executing some JavaScript. Can I do that?

I'm using jQuery to inject some additional HTML at the bottom of the page and I'd like to programmatically scroll to the position of that new content after it's added.

Thank you

rp

+4  A: 

window.scroll

KernelM
A: 

Another way to do this, so that you have the option:

In the HTML you are adding to the bottom of the page, you can insert a named anchor tag and then change the URL so that the page moves there (FYI: it will not refresh the page).

// add HTML like this, dynamically:
// <a name="moveHere" />

// the javascript to make the page go to that location:
window.location.hash = "moveHere";

Depending on what you are doing, this may or may not be a useful solution.

Jason Bunting