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

.clone().appendTo() gives me error not a function..

I don't understand why it gives me an error. What am I doing wrong? HTML

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
  <link rel='stylesheet' href='main.css'>
  <title>Document</title>
</head>
<body>
  <p class="hello">Hello</p>
  <div class="container"></div>
  <ul>
    <li class='item1'>Item1</li>
    <li>Item2</li>
    <li>Item3</li>
    <li>Item4</li>
    <li>Item5</li>
    <li class='item6'>Item6</li>
  </ul>


  <script   src="https://code.jquery.com/jquery-3.2.1.min.js"   integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="   crossorigin="anonymous"></script>
  <script src="javascript.js"></script>
</body>
</html>

CSS

.highlight {
  background-color: yellow;
}

JS

$('ul').click( ()=> {
  $('li:even').addClass('highlight');
  $('p').clone.appendTo('.container');
});

$('ul').dblclick( ()=>{
  $('li:even').removeClass('highlight');

});

javascript.js:3 Uncaught TypeError: $(...).clone.appendTo is not a function

2 Answers

Steven Parker
Steven Parker
243,266 Points

To call a method, you must put parentheses after the method name.

Even if you are not passing any arguments inside them, the parentheses still need to be there.

Oh Thanks! I see now the mistake, I forgot the parentheses! stupid mistake lol. thanks for pointing it out :P