tags:

views:

36

answers:

3

It looks like this:

var objDiv = document.getElementById("code");
objDiv.scrollTop = objDiv.clientHeight;

works in Chrome, but not FF, and this:

var objDiv = document.getElementById("code");
objDiv.scrollTop = objDiv.scrollHeight;

works in FF, but not Chrome.

Is there a better all around way to do this?

+3  A: 

How about placing an anchor at the very bottom of the div, and scrollIntoView() into it? That should work cross browser.

Pekka
Clever. I'll try that.
Rayne
@Rayne My link wasn't intended to point to Google, but the Mozilla docs. Corrected.
Pekka
A: 
objDiv.scrollTop = 100000; // or some other big number less than 2147483647
J-P
+1  A: 

Try window.scrollTo(0,objDiv.offsetTop+objDiv.offsetHeight);

KooiInc