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 Basics Working with Strings Display the Value of a String on a Page

MOSHE SCHWIMMER
MOSHE SCHWIMMER
6,301 Points

querySelector and innerHTML vs document.write

Why do we need this whole headache from querySelector and innerHTML , when u can use the "document.write" method, ?

1 Answer

Johnathan Guzman
Johnathan Guzman
7,432 Points

Hey Moshe ! The innerHTML property can be used to change any existing content(could be a blank space) whereas document.write can be used similarly without targeting any elements.

I hope this helps.

So, if you use innerHTML, you're adding it to the html file AND the .js file? In other words, one method adds it to two places (making it permanent) and the other one just keeps it in your .js file?