views:

62

answers:

3

IE displays a default scrollbar on the page, which appears even if the content is too short to require a scrollbar.

The typical way to remove this scrollbar (if not needed), is to add this to your CSS:

html {
  height: 100%;
  overflow: auto;
}

I'm trying to do the same thing in Javascript (without requiring that in my CSS), but I can't seem to find a way to get access to the <html> element. I know I can access the <body> element with document.body, but that doesn't seem to be sufficient, I need the wrapping <html> element.

Any tips?

+1  A: 

You're looking for the document.documentElement property.

SLaks
In IE, this element is only available in standards mode.
Marcel Korpel
Why was this downvoted?
SLaks
A: 

You can also reach the HTML element with:

var html = document.body.parentNode;
alert(html.nodeName);
Sarfraz
A: 

I guess for completeness' sake, I'll add another way to access it:

document.getElementsByTagName('html')[0];

Obviously this is a little more verbose, but it's always going to work regardless of the structure or standards-mode of your document.

eyelidlessness