Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript and the DOM The Browser Environment Accessing the DOM

Marlon Santos
Marlon Santos
2,676 Points

When I use the method document.body.remove() is it a window object method?

Once the window word may not be referenced, when I use document.body.remove(), am I using a window object method?

1 Answer

Travis Alstrand
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Travis Alstrand
Data Analysis Techdegree Graduate 49,443 Points

Hey Marlon Santos !

Great question,

When you use document.body.remove(), you are not directly calling a method on the window object. However, the document object itself is part of the window object in the browser environment.

Here's how it works:

window.document: The window object is the global object in the browser, and document is a property of this object. This means document is essentially shorthand for window.document.

document.body.remove(): This method is specifically a part of the DOM (Document Object Model) API, and it's a method available on a DOM element (in this case, document.body).

In summary, while you're not directly calling a method on the window object, the document is inherently tied to the window object, making it indirectly related. But document.body.remove() itself is a method of the HTMLElement interface, not the window object.