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 Working with jQuery Collections The .each() method

What am I missing? I am sure it is something simple that I should be able to easily remember...

I don't know why this is failing. Can you just point out what I am getting wrong here? I'll remember the correct answer and not ask about this again, promise.

index.html
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Document</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <h2>My Favorite Things</h2>

    <ul class="favorite-things">
        <li>Kittens</li>
        <li>Rainbows</li>
        <li>Unicorns</li>
        <li>Sprinkles</li>
    </ul>

    <script
    src="jquery-3.2.1.min.js"></script>
    <script src="app.js"></script>
</body>
</html>
app.js
$('.favorite-things li').each(function() {
  this.prepend('<input type="checkbox">');
});

1 Answer

Steven Parker
Steven Parker
231,269 Points

Within the callback, "this" represent an element, but "prepend" is a jQuery method. So you need to convert "this" into a jQuery object to use "prepend".

Also, the instructions specifically asked you to add "'<input type="checkbox"/>' to the beginning of each list item". Note that it's looking for the XHTML syntax that includes a slash. This wouldn't be necessary in actual practice, so you might want to report it as a bug to the Support folks.

Could you be more specific regarding the, "convert "this" into a jQuery object"?

Thank you