Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scrolling a div

Status
Not open for further replies.

crazyboybert

Programmer
Jun 27, 2001
798
GB
Hi All

I have a div with the following css

#myDiv{height:100px; overflow:auto; position:relative;}

The height of the content of the div is say 400px so a scrollbar is visible. I want to scroll the div to say 150px down.

I've tried using

document.getElementById("myDiv").scrollTo(0,150);

But get the error

"object doesn't support this property or method"

I'm guessing that you can only use scrollTo on the window object, which if that is the case is really naff! Now I am aware I could create custom scrolling using some nifty manipulation of the divs position and clip properties and then scroll it that way but boy thats a lot of effort for something fairly simple.

Anyone got an easy solution please. This is internal and for IE only so i'm not concerned in the slightest about any cross browser stuff.

Cheers

Rob

Go placidly amidst the noise and haste, and remember what peace there may be in silence - Erhmann 1927
 
Sorry all.

Googled "scroll div javascript" and the first result (this website) had my answer...

Code is

document.getElementById("myDiv").scrollTop = 150;

Must be because I'm tired from playing football on my lunchbreak [blush]

Rob

Go placidly amidst the noise and haste, and remember what peace there may be in silence - Erhmann 1927
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top