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 trialAriel Vainer
7,042 PointsinnerHTML?
Hi. Can someone please explain me what's the purpose of using .innerHTML? What does it mean?
2 Answers
Samuel Webb
25,370 PointsIt 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>
Ariel Vainer
7,042 PointsThank you!!
Samuel Webb
25,370 PointsNo problem.
Samuel Webb
25,370 PointsSamuel Webb
25,370 PointsAlso, you can do something like:
title.innerHTML = "Hello World";
To replace what's already inside of the selected element.