document.getElementsByTagName('html')[0].style; produces an error

  • Thread starter Thread starter AAaron123
  • Start date Start date
A

AAaron123

Warning 2 Error updating JScript IntelliSense: ..snip.. ColorScrollbar.js:
'document.getElementsByTagName(...).0.style' is null or not an object

I believe the following is what it is complaining about:

var htmlStyle = document.getElementsByTagName('html')[0].style;

I tried 'body' instead of "html" and got the same error in my error list
pane.

Do you understand what is wrong?


Thanks
 
I've never used document.getElementsByTagName, but something that the W3C
DOM specifies that you can use to reference the <body> tag is document.body.
This may not help in referencing the <html> tag, but it sounds like you can
survive with either one. Something else you could do is add an id attribute
to the <body> or <html> tag and use document.getElementById, which is
usually more reliable. You may also want to try writing some test code to
see exactly what is returned by document.getElementsByTagName('html') to
help you determine where the problem is. Good Luck!
 
AAaron123 said:
Warning 2 Error updating JScript IntelliSense: ..snip.. ColorScrollbar.js:
'document.getElementsByTagName(...).0.style' is null or not an object

I believe the following is what it is complaining about:

var htmlStyle = document.getElementsByTagName('html')[0].style;

I tried 'body' instead of "html" and got the same error in my error list
pane.

Do you understand what is wrong?


Thanks
Try getting the collection and making sure it is one. Some of the IE methods
incorrectly return single instances rather than collections when there is
only one.
var h = document.getElementsByTagName('html');
alert(h.length);
alert(h.innerHTML.substr(0, 100));
 
Back
Top