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

I'm appending the element correctly and placing it in the variable yet it's always returning wrong. Why?

I've been trying to append this element for a while and it shows up in the preview but it continues to return as wrong. Why is that?

index.html
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Document</title>
</head>
<body>
    <h2>Student List</h2>

    <ul class="student-list">
        <li>James McAvoy</li>
        <li>Alena Holligan</li>
        <li>Wade Christensen</li>
        <li>Matt Krzyzynski</li>
    </ul>

    <script
    src="jquery-3.2.1.min.js"></script>
    <script src="app.js"></script>
</body>
</html>
app.js
var $newStudent = $('.student-list').append("<li>Sam Smith</li>"); 

2 Answers

Stuart Wright
Stuart Wright
41,120 Points

You should not edit the line which you used to pass task 1. Instead create a second line which appends the element you created in task 1.

I tried that. It didn't work. Sorry.

Richard Hogge
Richard Hogge
26,808 Points

I believe Stuart is correct. Your code works, but splitting it onto two lines just makes it more readable:

Line 1 - Store the list item into your variable.

Line 2 - Append this variable to the unordered list.

Give that a shot.

If you're still stuck, I created a CodePen with my solve: https://codepen.io/tremolocreative/pen/ZreKao

Thank you so much. That was the fix!