# DOM

One of the things that sets NodeJS and JavaScript in the browser apart is the DOM. NodeJS does NOT have access to the DOM.

The DOM is NOT part of core JavaScript.

The DOM is an add-on that browsers get as part of the window object.

Everything you do in the browser, which is not part of core JavaScript, exists inside the window object. Because of this, You can write window as the first step in accessing an Object in the DOM OR you can omit it.

window.alert('This is a pop up message');
alert('This is also a pop up message');
//both these lines access the same alert method
1
2
3

# The Document Object

One of the objects inside window that you will access most is the document object. It contains all the methods and properties for working with HTML and CSS.

let h = document.querySelector('h1');
//find the first h1 element on the page
console.log(h.textContent);
//output the #text inside the h1 element.
1
2
3
4

We could, but typically do not, put window in front of the document.querySelector command.

Back to Week 5 main page

Last Updated: 9/29/2020, 10:17:59 PM