EN VI

Is there a reference to the <html> root element from the window object?

2024-03-12 17:00:09
Is there a reference to the root element from the window object?

After reading the MDN Article about the window.innerHeight, I want to use the <html> elements clientHeight property in some of my tests, as it is "the height of the window minus its horizontal scroll bar and any borders".

So I need a reference to the <html> element.

After examining the window object and the document object, the only way to obtain this reference is to query the dom. For example like this: const htmlElement = document.getElementsByTagName("html")[0];

I wonder if there is a better option? Maybe something simple like document.htmlElement?

Solution:

I think what you're looking for is

document.documentElement
Answer

Login


Forgot Your Password?

Create Account


Lost your password? Please enter your email address. You will receive a link to create a new password.

Reset Password

Back to login