JavaScript jQuery Basics Understanding jQuery Events and DOM Traversal Adding New Elements to the DOM

Jiten Mehta
Jiten Mehta
Front End Web Development Techdegree Student 7,929 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,368 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!