Link to home
Start Free TrialLog in
Avatar of johnwood
johnwood

asked on

How to use scrollLeft?

Hi,

I must misunderstand something. I thought the following code will move the elements in body by 1000 and will show the number 1000:
document.body.scrollLeft=1000;   //Why nothing happened with this
alert(document.body.scrollLeft;     //Why this is zero?
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Try:
document.all.getElementByTagName("body")[0].scrollLeft
Furthermore, I believe it works only for IE.
More info here:
http://www.java2s.com/Code/JavaScriptReference/Javascript-Properties/scrollLeft.htm

ASKER CERTIFIED SOLUTION
Avatar of TName
TName

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TName
TName

@hielo

   document.all.getElementByTagName("body")[0]
will not work as a way of accessing the body element. It should be
  document.getElementsByTagName('BODY')[0]  
so "document." instead of "document.all" and there should be a (plural) "s" - "Elements"...
Avatar of johnwood

ASKER

Thank you hielo and TName!

TName,
I have just tried your code and it worked. However, if I delete the first line
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
it would not work anymore!!! Very strange!!!
That's due to the fact that IE will behave differently in this respect if in strict vs. quirks mode. Have a look e.g. here:
    http://www.quirksmode.org/viewport/compatibility.html