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!

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

Please help. I've hit a bump and i am trying to understand how to solve this.

Can anyone help me out on this?

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

    <ul class="favorite-things">

    <script src="app.js"></script>
$('.favorite-things li').each(function() {
  // Write code here
   const href = $('li');

2 Answers

The challenge was to prepend a checkbox to a li. In an jQuery $().each loop this references the li element (In this case).

Inorder to prepend a element you have to define it:

var checkbox = '<input type="checkbox"/>';

And prepend it via jQuery:


Do not forget $() inorder to use jQuery

So I tried that.. $('.favorite-things li').each(function() { // Write code here var checkbox = '<input type="checkbox"/>'; $(this).prepend(checkbox); });

and it told me AST unexpected node call pass expression: Literal..

Hi, Brian

Sorry I don't know what this error means(maybe a bug in workspaces because I can not find any explanation in the web), but if you pass the string directly to the prepend method like this

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

Hope this works Know this works