- Now that you know what objects are, let me tell you something that will expand your perception of objects significantly. The browser is an object, and the document it displays is an object too. The browser itself has a long list of objects including: the browser window, the document inside the window, the navigation buttons, the location or URL, and more. These objects are modelled by what's known as the Browser Object Model, or BOM for short.
Because all these things are just objects, we can interact with them using JavaScript the same way we interact with any other object. If you want to know the width of the current viewport, you can simply ask for the window object, and its inner width property: window.innerWidth. If you want to open a new tab you use the window open method. Window is the top-level object in the BOM, and it has a ton of properties and methods you can use to interact with the browser itself, and what it displays.
You can see a list all the properties and methods for window in the documentation page on Mozilla Developer Network. You'll interact with some of the BOM objects from time to time, but the majority of them are mainly left to themselves since they are standard browser features and behavior. The exception is document, one of the properties in the window object, which contains the current HTML document. To get the document object you can call window.document.
But, since JavaScript typically lives inside the window, so inside the window object, you can get the document by simply calling it directly: document. Document, in turn has its own object model, the Document Object Model, or DOM for short. If you've worked with HTML and CSS before, you're already intimately familiar with the DOM, even if you didn't know it existed. The Document Object Model is the model of the document that forms the current webpage.
In HTML, every piece of content is wrapped in a beginning and end tag creating an HTML element. Each of these elements is a DOM node, and the browser handles each of them the same way it would handle an object. That's why when you target something with a CSS rule, say all anchor tags within the document, that rule is implemented to each of them individually. When you write a CSS rule targeting a, you're saying: "find me every a node, and apply the following style property settings to it".
When a document is loaded in the browser, it is loaded into the document object in the BOM, and a Document Object Model is created for just this document instance. The browser now creates a node tree, modelling the relationships between the different nodes. In a standard HTML document you'll have an HTML object containing two nodes: head, and body. Head holds all the invisible objects like title, link, meta, script, etc., while body holds all the visible nodes in the viewport.
These nodes in turn live in strict hierarchical relationships depending on how they are nested in the HTML. So, for example, a link in my menu is an a node, inside an li node, nested inside a ul node, nested inside a nav node, nested inside a header, nested inside the body node, nested inside the HTML node, nested inside the document object, nested inside the window object. You get the idea. You can see the code version of the DOM if you go to the Elements tab in Developer Tools in your browser.
Here you can select any node within the DOM, and see what styles are applied to that node.
Author
Updated
4/1/2019Released
5/17/2017Through practical examples and mini-projects, this course helps you build your understanding of JavaScript piece by piece, from core principles like variables, data types, conditionals, and functions through advanced topics including loops, closures, and DOM scripting. Along the way, you will also be introduced to some ES6 and the basics of JavaScript libraries.
- What is JavaScript?
- Working with data
- Using functions and objects
- Working with JavaScript and the DOM
- Changing DOM elements
- Handling events
- Working with loops
- Making images responsive using markup
- Troubleshooting code
- Validating functionality
- Minifying JavaScript
Skill Level Beginner
Duration
Views
Related Courses
-
Introduction
-
Welcome1m 7s
-
-
1. JavaScript: An Introduction
-
What is JavaScript?2m 38s
-
-
2. The Basics
-
Introducing the browser console10m 31s
-
3. Working with data
-
Data types in JavaScript4m 2s
-
Arrays2m 20s
-
4. Functions and Objects
-
Functions in JavaScript3m 28s
-
Build a basic function3m 29s
-
Anonymous functions5m 11s
-
Variable scope3m 17s
-
ES2015: let and const6m 12s
-
Make sense of objects3m 19s
-
Object constructors6m 16s
-
Closures8m 11s
-
-
5. JavaScript and the DOM, Part 1: Changing DOM Elements
-
Access and change elements4m 33s
-
Access and change classes3m 45s
-
Access and change attributes4m 53s
-
Add DOM elements6m 56s
-
6. Project: Create an Analog Clock
-
Use CSS to move clock hands3m 49s
-
7. JavaScript and the DOM, Part 2: Events
-
What are DOM events?1m 31s
-
Some typical DOM events1m 59s
-
Add and use event listeners6m 51s
-
-
8. Project: Typing Speed Tester
-
Rundown of HTML markup2m 58s
-
Build a count-up timer5m 56s
-
Add a reset button5m 3s
-
-
9. Loops
-
Loops3m 37s
-
Looping through arrays4m 7s
-
Break and continue loops7m 9s
-
-
10. Project: Automated Responsive Images Markup
-
Project breakdown1m 55s
-
Rundown of project setup3m 26s
-
-
11. Troubleshooting, Validating, and Minifying JavaScript
-
Troubleshooting JavaScript7m 20s
-
Online script linting5m 57s
-
Automate script linting8m 24s
-
Online script minification2m 50s
-
Automate script minification2m 24s
-
12. Bonus Chapter: Ask the Instructor
-
What are arrow functions?3m 11s
-
What does the % symbol do?3m 47s
-
-
Conclusion
-
Next Steps1m 55s
-
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.
CancelTake notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.
Share this video
Embed this video
Video: DOM: The document object model