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 Loops, Arrays and Objects Tracking Multiple Items with Arrays Using For Loops with Arrays

Ivana Lescesen
Ivana Lescesen
19,442 Points

What is the purpose of building a HTML list in javascript? Can't we build it in html

Hello everyone :)

Would someone please explain the What is the purpose of building a HTML list in javascript? Can't we build it in html file?

Matthias NΓΆrr
Matthias NΓΆrr
8,614 Points

With Javascript you can dynamically add HTML-Elements to your website. If you use only HTML, then this HTML is shown fixed on your site.

You can for example tell Javascript to show HTML-Elements on the website if a user presses a button and hide the same HTML-Elements when an other click with the mouse is made. Using these Javascript methods on your website is made easier by using a Javascript framework like jQuery.

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

You could. But what about this scenario: What if you don't know how many items are supposed to go in the list?

Imagine for a second you have a website (similar to Trello) where users can make a ToDo list. And each item they add is formatted as a <li> item. You have absolutely no way to know how many items they may want to add. Instead you could have JavaScript add each item to an array and then build up a list from that array. This makes your code and website much more flexible :smiley:

Ivana Lescesen
Ivana Lescesen
19,442 Points

Thank you so much, I constantly in awe about how great the treehouse community is. It is a true pleasure to learn and grow with all of you :)

thank you so much for the clear answer, I had the same question too ! kudos to our community!