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

my code is not working, I couldn't find any error

    $(this).html("<strong>Location:</strong> Your house?!");
  function() {
    $(this).html("<strong>Location:</strong> Treehouse Adoption Center");
//add a pet to the page with user input

$('#add-pet').on('click', function(){
// Grab info from the form

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

// Assemble the HTML of our new element with the above variables

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 the new element to the page


and it's not working :( , any solutions

1 Answer

Steven Parker
Steven Parker
230,230 Points

I'd need to see the HTML also to be more specific but potential issues are:

  • you may need to prevent the default form action or a page reload will clear the added elements
  • I'd guess "$("posted-pets")" probably refers to an ID and should have "#" in front

I checked the $("posted-pets") and found that it was a class, so I added a dot to be $(".posted-pets") and it works ^_^, thanks a million :)