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 trialFarid Wilhelm Zimmermann
16,753 PointsWhy cant I use $('#modal').append?
In this code challenge, we were supposed to append a dismiss button unto a <div> with the id="modal". This div gets saved as a jQuery Object into a variable called $modal.
obviously, ----- $modal.append($button); ----- works to append the button object unto the modal,
but when I tried selecting the <div> using its #id name like $('#modal').append($button);
So do I have to predefine jQuery objects as variables to use further methods on them?
1 Answer
Steven Parker
231,275 PointsThe reason "$('#modal').append($dismissButton);
" would not work is that you are attempting to do it before the modal div has been placed on the document.
Farid Wilhelm Zimmermann
16,753 PointsFarid Wilhelm Zimmermann
16,753 Pointsthanks a lot mate, that cleared up the confusion!