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 Introduction to jQuery DOM Manipulation Adding Content to the Page

Duy Khanh
PLUS
Duy Khanh
Courses Plus Student 4,911 Points

I do the same code like video why my code not working ?

Here is my code :

var $name = $('#pet-name');
var $species = $('#pet-species');
var $notes = $('#pet-notes');

var $newPet = $(
   '<section class="six columns"><div class="card"><p><strong>Name:</strong> ' + $name.val() + 
   '</p><p><strong>Species:</strong> ' + $species.val() +  
   '</p><p><strong>Notes:</strong> ' + $notes.val() + 
   '</p><span class="close">&times;</span></div></section>'  
);
//Attach new pet
$('#posted-pets').append($newPet);

2 Answers

Valeshan Naidoo
Valeshan Naidoo
27,008 Points

Have you added the click event listener function that wraps all this? I can't see anything else, but could be wrong.

Thomas Pans
Thomas Pans
9,428 Points

try adding .val() , this is what made it work for me.

But as the guy above me already said i can't see the rest of your code.

+ var $name = $('#pet-name');
+ var $species = $('#pet-species');
+ var $notes = $('#pet-notes');
          ```

Becomes -->


```html
+ var $name = $('#pet-name').val();
+ var $species = $('#pet-species').val();
+ var $notes = $('#pet-notes').val();
          ```