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 trialAhmed Mohamed Fouad
11,735 Pointsmy code is not working, I couldn't find any error
$('.loc').hover(
function(){
$(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">×</span></div></section>'
);
// attach the new element to the page
$('posted-pets').append($newPet);
});
and it's not working :( , any solutions
1 Answer
Steven Parker
231,269 PointsI'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
Ahmed Mohamed Fouad
11,735 PointsAhmed Mohamed Fouad
11,735 PointsI 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 :)