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 trialJulien Arseneau
Full Stack JavaScript Techdegree Student 5,200 PointsWhat is my error?
It says: ''There was an error with your code: TypeError: 'undefined' is not a function (evaluating 'this.prepend('<label> <input type="checkbox"/> </label>')')''.
<!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() {
this.prepend('<label> <input type="checkbox"/> </label>')
});
3 Answers
Dale Severude
Full Stack JavaScript Techdegree Graduate 71,350 PointsHey Julien,
Your code should be a jquery statement and begin with $. (this) should have curly braces around it. You have an extra label element in your code that is not needed. And finally add a semicolon at the end of your statement.
Dale Severude
Full Stack JavaScript Techdegree Graduate 71,350 PointsYou will need to post your code again to debug this.
Julien Arseneau
Full Stack JavaScript Techdegree Student 5,200 PointsI had accidently added a typo, now it works, thanks for the help!
Julien Arseneau
Full Stack JavaScript Techdegree Student 5,200 PointsJulien Arseneau
Full Stack JavaScript Techdegree Student 5,200 PointsThanks, but now that I corrected this it says: ''Within the anonymous function passed to the "each" method call, did you supply the argument "'<input type="checkbox"/>'" to the "prepend" method call on the jQuery object with an argument of "this"?''.