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.
Jiten MehtaFront End Web Development Techdegree Graduate 21,209 Points
Adding new elements to the DOM code challenge
Hi guys, I can't see where I'm going wrong here.
The code challenge is asking me to add in a new li element containing the student name Sam Smith using Jquery.
When I preview the HTML, the name has been added to the ul. Why do I keep failing?
This is the code I put in
const $newStudent = $('.student-list').append('<li>Sam Smith</li>');
Louise St. Germain19,412 Points
The challenge is expecting that the variable $newStudent contain only the new element created, and that you will then use that variable name to append it to the list.
If you got to step 2 of the challenge, I assume that you correctly figured out the first part, creating the new element:
const $newStudent = $('<li>Sam Smith</li>');
So from here, just add a second line where you append $newStudent to the class .student-list, like in the video Adding New Elements to the DOM. In other words, just break your previous code into two steps.
I hope this helps!