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/ quiz question one.

Inside the jQuery each() method, use prepend() to add an '<input type="checkbox"/>' to the beginning of each list item. Use the this keyword, so the callback function doesn't need any arguments.

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

Hey Myron, Give this a shot ;)

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

GoodLuck!

5 Answers

Credit to @Gary Hannon

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

So having a space between the checkbox type attribute does not pass the challenge

// Does NOT pass
'<input type="checkbox" />'

// PASSES
'<input type="checkbox"/>'

I don't know if it is intended, at least it works having a space between the attribute and the closing element tag when using my own editor testing it in the browsers. Got me stuck for a bit :)

Thanks

//Why doesn't this work

const inputBox = $('<input type="checkbox"/>');

$('.favorite-things li').each(function() {

$(this).prepend(inputBox); });

here is the code I used to complete the challenge

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