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

Could not understand the source code!

I could not understand the source code in this lesson: var $newPet = $( '<section class="six columns"><div class="card"><p><strong>Name:</strong> ' + $name + '</p><p><strong>Species:</strong> ' + $species +
'</p><p><strong>Notes:</strong> ' + $notes + '</p><span class="close">Ɨ</span></div></section>'
);

Can anybody have time to explain me line by line the above codes? Thanks in advance.

var $newPet

-- You've instantiated a new variable called newPet and you're populating it with...

$( '<section class="six columns"><div class="card"><p><strong>Name:</strong> ' + $name + '</p><p><strong>Species:</strong> ' + $species +
'</p><p><strong>Notes:</strong> ' + $notes + '</p><span class="close">Ɨ</span></div></section>'
);

-- This is simply a load of markup that you've got as a STRING. every time you're doing '+ $name +' or '+ $species +' you are simply concatenating whatever is in that variable to the overall string.

After you've instantiate the $newPet variable you can simply append it to the DOM..

NOTE: There is nothing special about starting the variable name with the $, I believe it's just a common coding convention used among coders who want to easily identify when they're doing something with JQuery.

If you need to know anything else then just post back.

1 Answer

Thanks Owen. I appreciate that.