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 and the DOM (Retiring) Making Changes to the DOM Getting and Setting Text with textContent and innerHTML

InnerHTML and textContent

I already watch the tutorial, but both sides can change text, whats the really difference between this two? Thank you so much.

1 Answer

Kieran Barker
Kieran Barker
15,028 Points

The innerHTML property lets you insert HTML into an element, whereas the textContent property only lets you insert text.

If I had a div element and I set its innerHTML to <h1>Title</h1>, then this new H1 element would be inserted into the element. But if I used textContent, then the H1 opening and closing tags would literally just show as text and would not be rendered as an H1 element in the HTML.

Thank you so much!! You explained very detailed!