JavaScript jQuery Basics Working with jQuery Collections The .each() method

I'm still lost...I think I'm about to give up

I'm sorry I'm so slow at this!

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() {


  const $checkbox = $('<input type="checkbox"/>');
  $(this).prepend($checkbox);

});

2 Answers

Just pass the checkbox to the prepend method as an argument and you should pass:

$('.favorite-things li').each(function() {
  $(this).prepend('<input type="checkbox"/>');
});

Thank you Scribbles! It works :)