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 trialkingdavid igbayilola
8,678 Pointsjquery .each() method
getting an error
<!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>
$('.favorite-things li').each(function() {
// Write code here
const list = $(this).attr('li');
$(this).parent().prepend('<input type="checkbox"/>');
});
2 Answers
Steven Parker
231,261 PointsYou're pretty close, but I see two issues:
- the assignment of "list" is unnecessary (and it is not used)
- the "parent" is not needed, "prepend" should be applied directly to $(this)
For future questions, please describe the issue in more detail.
Abdul Azeez
3,884 Pointshey man, whats up...are you nigerian
kingdavid igbayilola
8,678 Pointskingdavid igbayilola
8,678 Pointswhy is the parent not needed and the list variable
Steven Parker
231,261 PointsSteven Parker
231,261 PointsYou created "list", but you weren't using it for anything.
And the task asks you to add a checkbox to the beginning of each list item, and the list item is what "this" represents.
Also, if you take the "parent" you get the list itself (ul), and it's not correct HTML to add anything to a list other than another list item.
kingdavid igbayilola
8,678 Pointskingdavid igbayilola
8,678 PointsThanks !
kingdavid igbayilola
8,678 Pointskingdavid igbayilola
8,678 PointsAre you on any tree house group
Steven Parker
231,261 PointsSteven Parker
231,261 PointsI don't know what you mean, what's a "tree house group"?
kingdavid igbayilola
8,678 Pointskingdavid igbayilola
8,678 Pointshttps://teamtreehouse.com/account/users
Steven Parker
231,261 PointsSteven Parker
231,261 PointsThat must be related to the kind of subscription you have.
When I go to that link, I see "Bummer! You must be an organization administrator.".