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=1 000; //Why nothing happened with this
alert(document.body.scroll Left; //Why this is zero?
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=1
alert(document.body.scroll
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@hielo
document.all.getElementByT agName("bo dy")[0]
will not work as a way of accessing the body element. It should be
document.getElementsByTagN ame('BODY' )[0]
so "document." instead of "document.all" and there should be a (plural) "s" - "Elements"...
document.all.getElementByT
will not work as a way of accessing the body element. It should be
document.getElementsByTagN
so "document." instead of "document.all" and there should be a (plural) "s" - "Elements"...
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!!!
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
http://www.quirksmode.org/viewport/compatibility.html
document.all.getElementByT
Furthermore, I believe it works only for IE.
More info here:
http://www.java2s.com/Code/JavaScriptReference/Javascript-Properties/scrollLeft.htm