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 JavaScript and the DOM (Retiring) Traversing the DOM Getting All Children of a Node with children

Why does he give arguments to the function at the end?

he gave an argument to the function in the last step somewhere at 5 mins, why did he do that? he didnt have any arguments to the function when he made it, why didint it say error?

3 Answers

Steven Parker
Steven Parker
218,845 Points

At about 2 mins in the video, you can see that the "attachListItemButtons" function takes one parameter named "li", which represents the element that the new buttons are added to.

Aakash Srivastav
Aakash Srivastav
Full Stack JavaScript Techdegree Student 11,625 Points

As you can see attachListItemsButtons accept an argument li , which will be the current li item where the buttons are added to. Now whenever you will call the attachListItemsButtons , you have to provide it an argument , so he does. lis[i] represents a single li element on which button is added. Hope it helps.

But why???

I get that he gives the "li" argument, but I don't get the reason...

I simplified the example to test if you had to give the li (as in list element) for the argument, but it works with anything there.

Is it kinda like the event object?

const parent = document.getElementsByTagName('ul')[0];
const child = parent.children;

const newButtons = whatever => {

  let button = document.createElement('button');

      button.className = 'button';
      button.textContent = 'Button';



for (let i = 0; i < child.length; i += 1) {

You can check it in https://codepen.io/danvao/pen/ERPxOq

Steven Parker
Steven Parker
218,845 Points

I don't understand what you mean by "it works with anything there". Your code is passing each of the list items now, but if you change the argument in your call, you will not get any buttons:

  newButtons("anything");  // insead of: newButtons(child[i])