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 trialKevin Beall
13,828 Pointshow does the .append() function work?
I am a little confused about how the append function works. I understand that it adds the content to the end of the <div> for example.
Where i'm confused is....
var $select = $("<select></select>");
var $option = $("<option></option>");
$select.append($option);
The way I understand this is that the <option> goes inside the <select>. But how does this happen? If we are appending <option> to the end of <select> does it not show like this?
<select></select>
<option></option>
how does it do this?
<select>
<option></option>
</select>
1 Answer
Sean T. Unwin
28,690 PointsAppend places content before the end, yet inside the parent. This means that if there was other content within a div
, for example, the appended content would be after the existing content, but before the closing div
tag.
I hope that clears things up a little for you.