2

Possible Duplicate:
How to go to a specific element on page?

I would like to scroll to variable p as defined in the code below. is there a function i can use to scroll to it with javascript (not jquery). its a list item sitting inside of a scroll-able div, inside an un-ordered list.

var x = document.getElementsByClassName('listSection') [0].getElementsByTagName('ul')[0];
var p = x.lastChild;

Community
  • 1
  • 1
ModS
  • 806
  • 2
  • 15
  • 28

2 Answers2

2

element.scrollIntoView is probably what you are looking for. If not, it's at least worth a shot:

https://developer.mozilla.org/en-US/docs/DOM/element.scrollIntoView

Matt Greer
  • 60,826
  • 17
  • 123
  • 123
0

I think this could help:

var x = document.getElementsByClassName('listSection') [0].getElementsByTagName('ul')[0];
var p = x.lastChild;
window.scrollTo(0, p.offsetTop);