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 jQuery Basics Understanding jQuery Events and DOM Traversal Adding New Elements to the DOM

Jiten Mehta
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jiten Mehta
Front 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?

Help!

This is the code I put in

const $newStudent = $('.student-list').append('<li>Sam Smith</li>');

1 Answer

Louise St. Germain
Louise St. Germain
19,424 Points

Hi Jiten,

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!