JavaScript jQuery Basics Working with jQuery Collections The .each() method

Seth Pabst
Seth Pabst
8,608 Points

Can anyone point out the syntax error in this problem?

Don't know what I'm doing wrong

<!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
  this.prepend('<input type="checkbox"/>');

1 Answer

Steven Parker
Steven Parker
194,522 Points

The "this" inside an "each" refers to a DOM element. So to be able to call jQuery methods, you need to convert it to a jQuery object ("$(this)").

Seth Pabst
Seth Pabst
8,608 Points

Oh I see thanks:)