Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript and the DOM (Retiring) Traversing the DOM Getting All Children of a Node with children

Nour El-din El-helw
Nour El-din El-helw
8,241 Points

adding the button to the constant 'lis'

On 4:43 the teacher said he'll store the button in the constant 'lis' and select them with the children property. Did he mean he'll store the list items? I don't get it, Can someone please explain?

1 Answer

Marco Cornejo
Marco Cornejo
3,412 Points

Yes, lis is an array containing the list of items children to ul.

Once he has that, he proceeds to iterate within the array, and adds the buttons on all of them with the function attachListItemButtons(li) that he previously created.

const listUl = listDiv.querySelector('ul'); // <ul> with multiple <li> children elements.
const lis = listUl.children; //an array with all the lists found as children of <ul>

function attachListItemButtons(li){
     //Adds buttons with document.createElement('button');
}

//Finally, a for loop, where he iterates on lis.length, to give every list item multiple buttons.