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 JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Build a Quiz Challenge, Part 2

Pete Lower
Pete Lower
17,225 Points

The 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
Steven Parker
231,275 Points

:point_right: You 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
Pete Lower
17,225 Points

Thanks Steven, I'll use that in the future (with care!).