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 trialammarkhan
Front End Web Development Techdegree Student 21,661 PointsWhy LI was passed as an argument in function?
Why was LI passed in as an arguement to
attachListItemButton(li){
}
1 Answer
Steven Parker
231,261 PointsThe purpose of the function is to create and attach buttons to a list item. The "li" argument represents the particular list item that the buttons will be added to, and is needed by the function to do the job.
As you continue with the creation of the function in the video, you will see where "li" is used with the "appendChild" method to be sure each button is added in the right place.
Scott Wells
8,715 PointsScott Wells
8,715 PointsSo is the "li" in this case an actual HTML element, or is it simply a variable that can be targeted by ".appendChild" or does it even matter? (I'm still trying to understand what situations call for a parameter to be passed in a function. Thx)
Steven Parker
231,261 PointsSteven Parker
231,261 PointsIt's both. Since it is an element, it is also a candidate to be a "parent" to another element "child".