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

Ariel Vainer
Ariel Vainer
7,042 Points

innerHTML?

Hi. Can someone please explain me what's the purpose of using .innerHTML? What does it mean?

2 Answers

Samuel Webb
Samuel Webb
25,370 Points

It will return the content that is inside of the selected HTML element.

<h1 id="title">Hello</h1>

<script>
    var title = document.getElementById("title");
    console.log(title.innerHTML); // output => "Hello"
</script>
Samuel Webb
Samuel Webb
25,370 Points

Also, you can do something like:

title.innerHTML = "Hello World";

To replace what's already inside of the selected element.