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
Myron Miller
Front End Web Development Techdegree Graduate 17,364 PointsjQuery 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); });
5 Answers
Zach Freitag
20,341 PointsCredit to @Gary Hannon
$('.favorite-things li').each(function() { $(this).prepend('<input type="checkbox"/>'); });
kevinardo
Treehouse Project ReviewerSo 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 :)
Myron Miller
Front End Web Development Techdegree Graduate 17,364 PointsThanks
Caleb Taylor
6,108 Points//Why doesn't this work
const inputBox = $('<input type="checkbox"/>');
$('.favorite-things li').each(function() {
$(this).prepend(inputBox); });
luther wardle
Full Stack JavaScript Techdegree Student 18,029 Pointshere is the code I used to complete the challenge
$('.favorite-things li').each(function() { $(this).prepend('<input type="checkbox"/>'); });
Gary Thomas
6,893 PointsGary Thomas
6,893 PointsHey Myron, Give this a shot ;)
$('.favorite-things li').each(function() { $(this).prepend('<input type="checkbox"/>'); });
GoodLuck!