Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Interacting with the DOM!
You have completed Interacting with the DOM!
Preview
We can use properties to select elements based on their relationships with other elements. Here we'll select all the children of an element with the children property.
Code Snippet
btnCreate.addEventListener('click', () => {
let ul = document.getElementsByTagName('ul')[0];
const input = document.querySelector('.input-main');
let li = document.createElement('li');
li.textContent = input.value;
ul.appendChild(li);
input.value = '';
});
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
or traverse the DOM using
properties of DOM nodes.
0:00
Like event handling,
traversing the DOM relies on selection.
0:01
So far, we've been starting at
the top of the DOM tree to select our
0:07
element using the document object.
0:11
However, you will often have times when
you already have a reference to one
0:14
element, and you need to get
a hold of another element nearby.
0:18
This is called DOM traversal.
0:22
Traversal is just a way to move from
one part of the DOM to another and
0:25
select an element based on its
relationship with another element.
0:29
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up