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

Why is it that appending .innerHTML to document.querySelector('main') will not work?

In one of the solutions, Guil provided a constant variable with document.querySelector('main'):

const main = document.querySelector('main');

Then, when outputting html to the main html tag, he provides:

main.innerHTML = **HTML CODE**;

How does this work and not:

document.querySelector('main').innerHTML = **HTML CODE**;

Am I missing something here? Are we only able to perform one property or method? I might have overlooked something from previous videos.

Thanks in advance.

1 Answer

Steven Parker
Steven Parker
231,141 Points

Both techniques should work, but of course you need to provide actual HTML instead of "**HTML CODE**".

For example:

document.querySelector('main').innerHTML = "<h1>Look! It works!</h1>";

That's bizarre, It works now!

I reviewed code multiple times, and even placed on a separate IDE. Fatigue? Maybe...

Thank you for clearing that up and reassuring me!