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

I got confused with the way she places quote marks in the code.

Hello, as I was watching this video I followed along with the teacher and I tried to do what she said that was going to do. I paused the video and I tried but I saw that she puts quote marks only in the posted-pets, why? I got a bit confused with this even with normal Js but I didn't ask about it. Here is the code ==> $('posted-pets').append($newPet); Can someone enlighten me ?

Thank you very much and I am sorry for my poor grammar.

1 Answer

Stephan Olsen
Stephan Olsen
6,650 Points

It's really just the syntax jQuery uses to select elements. The selector function in jQuery takes a string as parameter, which is why you need to use the quotemarks. In plain JavaScript you would get an element by doing something like this:

// Get by class name
document.getElementsByClassName('myClass');

// Get by ID
document.getElementById('myId');

// Get by css selectors
document.querySelectorAll('.myClass #myId h1');

jQuery just has a shorter syntax, that works quite similar to the querySelectorAll in JavaScript. You define what you want to select by using its css selector.

$('#myId');
$('.myClass');
$('h1');