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 trialPete Lower
17,225 PointsThe new print method can only be called once, otherwise, the newly added content will override the current content.
I was using the print function in multiple spots instead of saving to a variable. Is there a way to append with the innerHTML method?
1 Answer
Steven Parker
231,269 PointsYou can append, but you need to be careful.
You can certainly write that assignment statement as an append instead:
outputDiv.innerHTML += message;
But you have to be careful that neither the current contents, nor the new message content being added, have tags (or are missing tags) that will cause the concatenated HTML to not make sense. If the element contains only text, and you're adding only text, you'll most likely be safe.
Pete Lower
17,225 PointsPete Lower
17,225 PointsThanks Steven, I'll use that in the future (with care!).