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 trialIvana Lescesen
19,442 PointsWhat 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?
2 Answers
Jennifer Nordell
Treehouse TeacherYou 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
Ivana Lescesen
19,442 PointsThank 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 :)
Jennifer Nordell
Treehouse TeacherIvana Lescesen You're quite welcome! Yes, I love this Community too! They've helped me soooo much
nagamani palamuthi
6,160 Pointsthank you so much for the clear answer, I had the same question too ! kudos to our community!
Matthias NΓΆrr
8,614 PointsMatthias NΓΆrr
8,614 PointsWith 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.