
Welcome to this course! I hope you enjoy it as much as myself. It has taken me several months of hard grueling work to put it together. I hope you appreciate this and take a lot from it.
The DOM is crucial for you to master if you want to take your web development career seriously. It is the building block of every website you visit. Although the DOM specifically refers to front end development, you can still use the concepts and methods learned in your backend development.
Before we begin, I want to address the 2 most common questions students ask me about the DOM when they start out -
Is the DOM a programming language?
Where does the DOM come from?
Are you ready to learn amazing things about the DOM
The name "Document Object Model" was chosen because it is ... surprise surprise ... an "object model". This means that our document is modeled using objects, and the model encompasses not only the structure of a document, but also the behavior of a document and the objects of which it is composed.
In other words, the DOM does not represent an abstract data structure, but rather, real live objects each of which have functions and their own unique identity.
To understand the DOM, lets build a simple page. This will help us to examine our code in more detail and figure out what the DOM is all about.
There is hierarchy everywhere - a CEO of a company, then managers of different divisions, and finally employees. In a family, there's the grandparents, the parents, and the children. Just like a corporate or family structure, there is also hierarchy when it comes to the DOM. Its important for us to know this hierarchy - it tells us where all the methods and functions we get are coming from.
Enjoy!
The console is given to us by the browser, and allows you to run and execute JS.
But it does more than that.
It also allows you to inspect objects and their properties. But you'll notice that some properties are bright purple, and others are faded. Why is that?
We've looked at the hierarchy of the DOM.
But lets take a further step back.
The browser object model (BOM) is a hierarchy of all the browser objects that are used to manipulate methods and properties associated with the Web browser itself.
Objects that make up the BOM include the window object, navigator object, screen object, history, location object, and the document object.
It can be quite confusing when starting out, what the BOM and DOM are. Here are my 2 cents worth.
Most people, when they're starting out, think that the DOM was designed for JavaScript.
As we will see, this is not the case. The DOM was made to be independent of any programming language. Sometimes this can cause weird effects (which we'll see later on in this course).
In fact, we don't have to use JavaScript to access the DOM. We can use, for example, Python.
Up until this point we have a very high level understanding of the DOM. I want to now dig deeper. But instead of showing you what the DOM is, I want us to look at what is NOT the DOM. I know, its a rather round-about way of looking at it, but I believe it is the best way.
Lets get down to business.
The DOM is not the same as your HTML code.
We've seen that the DOM is not the same as our HTML code, so you may think the DOM is what we see in the browser window when page loads.
Nope.
The DOM is not what you see in the browser.
So Clyde, the DOM is not our HTML, and its not what we see in the browser window. What then, is the DOM?
You may think its what we see in the DevTools.
You are 90% correct, but for reason's we'll discuss now, you'll see that its not 100% the same.
One reason why the elements inspector in DevTools is not the same as the DOM, is due to Pseudo Elements.
As I am sure you know, Cascading Style Sheets (CSS) is an independent language used to describe the presentation of web applications. This involves concepts like colors, fonts, and the full control of the layout of HTML elements. A CSS pseudo-element is a keyword added to a CSS selector that lets you style a specific part of the selected HTML element.
Confused?
Don't be. Lets jump into an example and see what this means.
A quick summary of what the DOM is not.
The closest approximation to the DOM that we have access to is the elements inspector in DevTools.
JavaScript is a programming language that the browser reads and does stuff with.
But the DOM is where that stuff happens. Many people get confused between JavaScript and the DOM, thinking that many things are a "JavaScript Thing" when in fact it is purely the "DOM API" doing that thing.
I hope you're starting to get more familiar with the DOM and starting to understand it. Don't worry if its still a bit fuzzy right now - by the end of the course you'll become very familiar with the DOM and what it is.
Keep going.
Great, we know what the DOM is, but this lecture now discusses why its important for us to know about the DOM and what we can do with it.
If you're anything like me, you are getting tired with theory.
So, lets jump into our text editor and look at how we can manipulate the DOM.
We've seen that the DOM defines how the contents of a page are modelled in the browser.
The DOM API, on the other hand, is how the browser provides access to this content.
For instance, calling document.getElementById(id) is the method defined in the DOM API to get an element with the given ID. There are many more, but this is a common example.
The DOM is used by most programming languages to make web pages dynamic.
DOM can be used in different environments.
Take a step back.
If you have a technical job, you may use words and jargon at work that is totally different to what you'll use when having a barbecue with friends over the weekend.
In both instances, however, you are speaking English. It just so happens your vocabulary changes depending on those around you and the context.
Its the same with JavaScript.
JavaScript lives in different environments - including frontend (the browser), backend (Node.js), and working with data (MongoDB).
Many developers get confused between JS and external APIs. Let me explain.
Lets look at an example, by using the setTimeout() function.
I'll use this example to explain the differences between the DOM and JavaScript.
We've built our example. Now its time to dive into what makes JavaScript from the DOM.
Many developers, including experienced ones, quietly blur the line between the DOM API and Web APIs. Both are provided by the browser and both are used from JavaScript, so it is easy to assume they are the same thing. They are not.
Because the DOM was not made purely for JavaScript, it can cause weird results.
Sometimes what you think is an array (because it looks and feel like an array) is not an array as we would expect. Lets look at this in more detail.
By mastering DOM access, you can create dynamic forms, update content in real-time, and optimize page performance. This knowledge is essential for building robust and responsive web applications that provide a superior user experience.
We've come a long way. Well done!
We've seen what the DOM is, and how it differs from JavaScript.
Now its time to look at how we can access the DOM.
Accessing and manipulating the DOM is fundamental to building funky websites.
A quick infographic explaining how you access the DOM.
Before we start diving into all the access methods, you have to understand your HTML. This course is not about HTML, but this lecture is a quick recap of the jargon we need to know in order to understand the methods later in this section.
This is a great lecture to get involved and start coding alongside me. We are building our page that we'll use for the remainder of this section.
If you really don't want to code this, then no stress - you can download the material which I'll make available for you.
I sometimes get asked how I can type so quickly in Visual Studio Code. Truth is, I use the help of extensions.
Confused? Don't be ...
Perhaps the most well known and common method, the getElementById() returns an element node with a specific ID.
Although this is a very simple method and performance efficient, there are also some downsides to using this method to access items in the DOM.
Watch this lecture to find out why!
getElementsByClassName() returns an HTMLCollection. For now, you don't have to stress about what exactly this means. Just know that its an alternative method to access items in our DOM.
The cool thing with this method is that you are able to collect a whole bunch of items, rather than just one element with a specific ID.
I want to put your knowledge to the test now.
Don't worry, its purely for your benefit and you should have a lot of fun doing it.
I would strongly encourage you to build this page with me. The more you code, the better you'll become.
However, if you are stubborn and really don't want to, then I have provided the blueprint code (without the solution) for you to download.
Lets now include all our class names to our HTML, and finish off the functions.
You see, its not that difficult is it?
Hope you had tons of fun.
This is closely related to getElementsByClassName, but getting 'tags' is even more broad. I say this because now we don't even have to have class names in our HTML - we can purely find an entire collection of HTML elements by their tag name.
Along came a spider .... oops, wrong song.
Along came the Selectors API in 2003, which gave us access to the querySelector and querySelectorAll methods.
The method querySelectorAll() returns a NodeList, which acts like an array. That list is "static", which means that the list won't update even if new matching elements are added to the page. Worried? Don't be, we'll cover Nodes and live vs static lists in the bonus section next. For now, just understand that there are now querySelectors that we have access to.
Lets jump into it.
Actions speak louder than words, so this lecture takes a look at how we can use the querySelector to access items in our DOM.
We've learnt how to access the DOM with these methods:
document.getElementById
document.getElementsByClassName
document.getElementsByTagName
document.querySelector
document.querySelectorAll
With the query selectors, we use a CSS selector to define what elements to grab. This is why its important to understand our HTML and CSS to fully appreciate how these methods work.
In a few of the previous sections, I have mentioned the word 'nodes'. Cool word. But it also has very practical implications for us, which is why I wanted to dedicated an entire bonus section on Nodes.
The simple answer to what is a node is, is that its pretty much everything. I know, kinda not that helpful right?
So, each <p> tag, every <div> tag, even the text inside each tag is a node. Some are element nodes (such as the <p> and <div>) and some are text nodes. Some nodes are comments. The list goes on ...
But not everything is a node, such as attributes.
What exactly is a node?
Armed with the knowledge of what a node is, lets look at our code in more detail and practically see how nodes work.
Its time to jump back into coding again (YAY).
Before we start coding different types of nodes (which is coming up, I promise), I want us first to access the console. I want us to access the <head> element and see the nodes that are contained within it.
Enjoy!
Once again, lets turn to our trusted old friend - Visual Studio Code.
I would like to expand on our existing code and include a few different types of nodes.
This will naturally lead onto the next lecture where we discuss the different node types in more detail.
I wish coding was super simple ... it would make our lives a lot easier. But then again, we would become uncompetitive ... so maybe it is a good thing that coding is complicated.
I digress.
My point is that there is not just one type of node. There are different nodes, and this is important to us because each node has different methods and properties attached to it.
But you already know this.
Lets look
I understand this may be jumping the gun, but in order to fully appreciate nodes, you need to understand their relationship to each other. And just like a family tree, where you have grandparents, parents, and children, you similarly have a tree when it comes to nodes.
At this point you know there are a handful of node types (at the time of writing this, there are 8 node types), but how do we go about identifying what type of node we're dealing with at any given time?
We've used nodeName to access the name of the node type we're dealing with. But we also have tagName. Are they the same thing? Short answer is no, but this lecture will go into detail as to why they are different.
We've seen that there are 5 main access methods, being:
getElementById()
getElementsByClassName()
getElementsByTagName()
querySelector()
querySelectorAll()
And remember, each of these methods returns a special type of collection to us. Some return an element object, others an HTMLCollection, and others a NodeList.
An element object is pretty obvious, so in this lecture I want to look at the differences between an HTMLCollection and a NodeList.
I could have stopped at the previous lecture. That is, an HTMLCollection is a live collection, and a NodeList is a static one.
But if you're anything like me, this is just not good enough.
I need to see the comparison in a practical example.
Well my dear students, what are you waiting for. Lets get crackin'.
I'm super excited for this section - because now you are advancing and starting to understand what the DOM is.
Its time for us to learn how to not only access a specific item in the DOM (based on a class name for example), but also how to walk through the DOM.
Grab a coffee and get ready, because this section is going to be EPIC.
See you soon
A good JavaScript developer needs to know how to traverse the DOM—it’s the act of selecting an element from another element.
Traversing just means "moving through". It means we can find (or select) HTML elements based on their relation to other elements. In other words, we can start with one selection and move through that selection until you reach the elements you desire.
Pretty cool right.
Lets jump into it.
I always like to look at practical examples, which is why I want us to build a page that we will use throughout this entire section.
Sometimes, we don't know where we want to go.
Yes, we have various access methods available to us, like getElementById(), and query selectors, but sometimes we don't quite know what we're looking for. We just want to get in the car and drive...and hope we find what we are looking for.
When it comes to navigating the DOM, we'll find ourselves in this position all the time.
That's where the various built-in properties the DOM provides for will help us out, and we are going to look at those properties in this section.
Before we can find elements and do funky things with them, we need to first get them - i.e. we need to know where they are.
The easiest way to tackle this topic is to just start form the top and work our way down. And it all starts with the king of the browser ... the window object. As you now know, the DOM is made up of the window, document, and html elements.
Lets have look at these objects.
To master the DOM, you need to understand that all of our elements in the DOM have at least one combination of parents, siblings, and children to rely on.
But please don't get intimidated or worry, it works very similarly to your own family dynamics!
Don't get intimidated by all the new terminology you're learning.
Remember, a parent element is just an element that contains other elements.
This lecture takes a deep look into the parent node - and we also look at a practical example of its use.
Enjoy!
A sibling element is an element that has the same direct parent as other elements. Think about normal family dynamics - a sibling of yours shares the same parent. Its exactly the same with the DOM family.
The hardest part of traversing the DOM is understanding how children work. In this lecture we're going to talk about firstChild, lastChild and children.
Don't let all the detail scare or intimidate you. A 'child' element is just an element ONE level below its parent. It makes sense right?
Depending on your code setup, you may want to access or manipulate a DOM element that is in a certain location. That's why we have different methods such as accessing the firstChild, lastChild and children methods.
Don't worry if you don't quite understand. We'll see this in action.
We know the theory, but now its time to put your website development skills to the test. Here we look at some of the child methods in action.
The DOM API exposes us to a method called children.
The children property returns a collection child elements. And it gives us this collection as an HTMLCollection object. The elements in the collection are sorted as they appear in the source code and can be accessed by index numbers.
The childNodes property is a property of Node and is used to return a Nodelist of child nodes. Nodelist items are objects, not strings and they can be accessed using index numbers. Don't get fooled - the first childNode starts at index 0. This is true for most programming languages.
The children is a property of element which returns the child elements of an element as an HTMLCollection object.
At this stage in the course you already know that there are different types of nodes within our DOM. Its now time to put your knowledge to the test.
Grab a coffee, and enjoy!
Let us now go through the answer, by coding together.
Getting this stuff right is very important - it will enhance your web development skills and allow you to master front-end web development.
Hope you're learning a lot and enjoying this course so far.
Keep going. Stay motivated.
As you will recall, sibling elements are elements that share the same parent. Just like with parents and children, there are a few methods / properties that are given to us by the DOM that we can use to work with siblings.
Lets look at a few siblings methods in action. Practice makes perfect.
Well done. You're well on your way to mastering front-end web development. Seriously. I'm super impressed.
This entire section has covered how we can traverse (move around) the DOM. Its a crucial skill to have as a developer and will only assist you in getting ahead.
I hope you've had as much fun learning, as I have had putting it together.
See you in the next section!
If you though the previous section was good, hold onto your horses because this section is going to BLLLLLOW your mind. We are now getting into full DOM manipulation - that is, creating, removing and cloning elements in your DOM. This is the meat of front-end website development. Master this, and you'll be well on your way to becoming a full-stack web developer.
I always like taking a step back, so we don't get lost in all the detail.
Static websites are just ... boring. Our goal is to have the skills and ability to create dynamic websites that increase click-through rates, user experience and conversions.
In other words, we want to have the ability to change the DOM at our leisure, dynamically.
The most important skill you can learn as a front-end web developer is the ability to create elements dynamically and then add those elements to the DOM.
This is why we're going to spend a few lectures on this topic - so you can truly master it.
This is a very advanced topic on web development - a topic not many developers can even answer. We know that the keyword in the DOM is the document itself. It is this document that we use to interact with the DOM. But, as we have seen, this document inherits from the Document node. But what does this mean? Watch this lecture to find out.
Prototypes are a fundamental concept of JavaScript. They are used to implement inheritance, object creation, and other important features. It is therefore crucial that you understand prototypes – what they are, why they are there, how to use them, how to create them, and when to use them!
The inheritance of the document object from the Document node and the Node interface ensures a structured, consistent, and efficient way to interact with the DOM tree and its various elements within your web applications. In modern JavaScript, you'll rarely need to refer to the Document interface directly. Most of your interactions will be with the document object.
Lets use the most well-known method available to use to dynamically add elements to our application. Take it in, and enjoy!
As we've seen, creating the element is the easy part.
But without doing more, our newly created element will float round in space, all lost. In fact, if you want to get technical, memory space has been allocated for our newly created element, but we haven't attached it to anything. That's why we are unable to see it.
So, in order to finish things off, we need to attach our newly created element to a parent.
Just when you think we were done .... !!!!
But don't worry, you're almost there. We've created an element, and we've added it to the DOM. But up until this point, we haven't populated it with anything. It's like we've brought a plate to a diner at a restaurant, with no food on the plate!
We have a few options available to us to add content to a newly created element, but the one I want to look at is the textContent property.
We've seen the use of createElement, but in order to attach it to a parent we can append it to the parent. The appendChild() method adds a node to the end of the list of children of a specified parent node.
This lectures takes a deeper look into the appendChild method, and how it works.
The insertBefore() method inserts a node as a child, right before an existing child, which you specify.
Although there's an insertBefore() method, there is not an insertAfter() method yet at the time of this lecture in 2020. But don't panic, we have a solution.
As we've seen, there is no insertAfter() method. So then Clyde, how do we insert an element AFTER an element? Good question, and this lecture will give you a solution.
Great, you can add items to the DOM. But what if the user wants to delete an item from his shopping cart, for example? How can you deal with this? Easy. We can access a few DOM methods to remove elements from the DOM.
The removeChild() method in the DOM is used to remove a specified child node of the given element. In order for you to use this method, you have to call the method on the parent of the element you're wanting to remove.
And lastly, this method returns the removed node as a node object or null if the node doesn't exist.
The remove() method removes the selected element (i.e. the element that you attach this method to), including all text and child nodes. But be careful, because this method also removes data and events of the selected elements.
We've used 2 different methods to remove an element from the DOM, but which method was introduced first and which is best to use?
Being able to clone elements is very useful as a developer. It allows us to create a deep copy (if this is what you want, of course) of the selected DOM element including attributes and child elements. In other words, it creates a duplicate of the node on which this method was called. Makes sense.
The DOM cloneNode() method is used to copy or replicate a node on which the cloneNode() method is called. For example, a list item can be copied from one list to another using this method. It takes 1 argument, which is a Boolean value. If we leave it blank, then true is set by default, which means that by default both the element and all of its children will be cloned. Make sense right?
Are you curious how our clone method worked? If so, this lecture is perfect for you, as we jump into our <script> tag and take a deeper look at what we've just done.
It is always a good thing to test yourself - it not only solidifies what you've learnt, but also encourages you to keep going. You've come such a long way already - you know how the DOM works, where to find it, how to access it, and how to manipulate it. Its now time to put these skills to the test with this simple but fun example.
I hope you gave the previous test a go. It doesn't matter if you couldn't finish it - the important point is that you gave it a go.
In this lecture we will code up the solution together.
Enjoy!
Remember to laugh and have fun!
A quick outro and a huge THANK you for your continued support.
As you embark on your journey to further enhance your web development skills, I highly recommend considering taking my DOM Part 2 course
*** THIS COURSE IS A GAME-CHANGER ***
Elevate Your Skills: Master the Document Object Model (DOM) and take your coding to the next level.
Create Dynamic Web Apps: Learn how to use JavaScript and the DOM to build engaging, interactive websites.
Hands-On Learning: Dive into practical examples and performance analysis techniques.
Understand Relationships: Grasp Parent, Sibling, and Child DOM relationships for better manipulation of elements.
Unlock Your Creativity: Transform your ideas into reality by mastering front-end development.
Let me share my new front-end web development secrets with you
Understanding the DOM will equip you to become an awesome front-end programmer. Learn how to implement your creative, different and dynamic ideas into your website. Master front-end development and you’re half way to becoming a full stack web developer. Take control through understanding. Delivering an interactive web experience is challenging.
How exactly does the browser model your HTML, CSS, and JavaScript? Where can we access this model? What can we do with this model? How can we change this model? By understanding these questions, you will be able to access the DOM and better yet, manipulate it! In other words, you will be able to create dynamic apps that improve user engagement and experience.
What This Course Covers
This course is designed to provide you with a solid foundation in front-end web development. By the end of this course, you'll have a clear understanding of what the Document Object Model (DOM) is, how to access it, and how to manipulate it effectively. You’ll learn about nodes, HTMLCollections versus NodeLists, and much more!
In this course you’ll learn about front-end Web Development, by mastering the Document Object Model.
Why do you need to know about the DOM?
So, you know some HTML, you’ve created your first tags, learned about CSS, made awesome forms, star-gazing buttons, responsive pages and have started to create dynamic and interesting pages.
But now you want to do more: “How can I add animation (and life) to my page? I wish I could give an error message to a user who incorrectly submits a form!”
And this is where the DOM comes into the picture. and where this course(s) provide you with an opportunity to grow in your skills.
To cut a long story short, we use the DOM to allow users to interact with our app. It doesn’t have to be annoying interaction either – simple things like giving the user the ability to ADD/EDIT/DELETE/UPDATE contents on your page, for example, requires interaction with the DOM.
The first step in understanding the DOM is understanding what it is. How does it differ from your HTML markup? How does it differ from JavaScript? From there, you’ll start exploring and experimenting with tools to access the DOM. You’ll learn simple, yet very powerful strategies to access and traverse the DOM. We don’t stop here, but then get into more advanced things like manipulating the DOM (via the create and remove methods given to us by the DOM API).
Knowledge of the DOM is incredibly useful for understanding how your webpage can be improved.
By the end of this course, you'll be able to “speak” DOM by gaining an understanding of where you can find it, how you can access it, and more importantly, how you can manipulate it. We dig deeper in every lecture, learning about things like Nodes, the difference between HTTPCollections vs NodeLists, and a whole bunch more! This course has many bonus lectures which extend your knowledge base and test your skills.
Through practical examples, this course helps you understand the DOM piece by piece. And we use the latest and best features of JavaScript and browsers (like the new remove API) along the way so you can stay ahead of the pack.
*** A must-do Web Development course on Udemy ***
Successful programmers know more than rote learning a few lines of code. They also know the fundamentals of how your browser represents your HTML code and works behind the scenes. If you’re wanting to become a full stack developer, you need to know how to deal with the DOM. You need to know how to access it, how to manipulate it, and how to dynamically interact with it.
I want you to become a successful front-end programming Grandmaster.
I want you to be able to apply what your learn in this course to your webpage.
This course is perfect for you.
Description
Hi there, my name is Clyde and together we’re going to learn how successful web developers can create whizbang websites that are dynamic and engaging!
The root to understanding how to be a professional front-end web developer is understanding the Document Object Model and applying it to practical situations. We're going to practice and learn and emerge confident to tackle any challenges modern programs and websites throw at us.
After completing a few university degrees, and post graduate studies, I developed a fascination for web design and software languages. For several years I have immersed myself in this. I spent a fair bit on top courses and went on to apply the knowledge practically. I recognized gaps in some of the courses I’ve taken and hence my course teaches what I wish I was taught. My intention is to share the knowledge with you in an easy to follow manner, so that we can benefit together. You benefit form learning, and I from sharing in your success.
This course is for beginners and for intermediates.
A unique view
Understanding the DOM is a vast topic. To get you up to speed, I’ve spent months thinking about where to focus content and how to deliver it to you in the best possible way.
You will learn "why" things work and not just "how". Understanding the fundamentals of the DOM is important as it will give you infinite possibilities. Armed with this knowledge, you’ll be able to create applications that update the data of the page without needing a refresh. You will be able to create apps that are customizable by the user. You can even allow the user to drag, move, and delete elements. Can you begin to see how important the DOM is?
How is this course different?
There are lots of great courses that focus on web development. Pity they never get into the detail about how the Document Object Model works behind the scenes – a skill that every full-stack developer needs to master.
In this course, I focus on true web development in the front end. This includes understanding what nodes are, looking at the Document node (this is different from the document object by the way), understanding the DOM tree structure, what the different types of nodes there are, and how you can use the DOM to access elements on your page and manipulate them.
Practice makes perfect
Theory is theory … but there’s nothing like getting behind your computer and typing in code. That’s why we will be coding, laughing and pulling out our hair together as we code real life websites and exercises during this course.
I love practical examples, which is why we build simple pages and analyze the DOM together.
Is This Course Right for You?
Absolutely!
This course is suitable for all levels.
If you fall into any of these categories, this course is perfect for you:
Aspiring Programmers: Start your journey into programming with essential HTTP and JavaScript fundamentals.
Dynamic Website Builders: Learn how successful developers create engaging websites that stand out.
Front-End Enthusiasts: Gain a solid understanding of front-end web development.
Future Full-Stack Developers: Understand how JavaScript operates on the front end before diving into backend frameworks like Node.js.
Curious Learners: Explore how the Document Object Model works behind the scenes.
WHY START NOW?
Right this second, your competitors are learning how to become better web developers.
Web development is a blazing hot topic at the moment. But you have a distinct advantage. This course offers memorable learning topics, actionable tactics and real-world examples.
Lets get started!
What do you get?
Lifetime access to all tutorial videos. No fees or monthly subscriptions.
Q&A support.
Quizzes and challenges to help you learn.
I’ve allowed you to download all of my lectures for offline viewing.
Let's get excited about becoming a professional web developer, and to be able to confidently apply it to your own websites.
Let's get crackin'