Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript DOM Scripting By Example Editing and Filtering Names States of the Application

Nicholas Wallen
Nicholas Wallen
12,278 Points

Within the ul event listener, why is li referred to as a parent of ul? Isn't it the opposite?

ul.addEventListener('click', (e) => {

if (e.target.tagName === 'BUTTON') {

const button = e.target;

const li = button.parentNode;

const ul = li.parentNode;

3 Answers

From what you posted it looks like li is the parent of button and ul is the parent of li.

Othneil Drew
Othneil Drew
22,421 Points

"parentNode" is telling the browser to traverse the DOM to get the parent of the selected element.

const li = button.parentNode is finding the parent of the button and setting the li value to the button's parent. In this case the li element.

const ul = li.parentNode if finding the parent of the button and setting the ul value to the li's parent. In this case the ul element.

Andrew Tiller
Andrew Tiller
4,182 Points

<ul> is an "Unordered List" of <li> "List Items" which contain <button>s. button.parentNode will return the <li> the <button> is in. li.parentnode will return the <ul> that the <li> is in.

[element].parentNode doesn't assign something as a parent, it returns the parent of that element.