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

ian truong
ian truong
4,685 Points

text.content and innerhtml

i dont understand why we use text content and innerHTML to replace content or add buttons to the website when you can just do it in HTML itself?

1 Answer

Joseph Wasden
Joseph Wasden
20,406 Points

HTML is used to display structured information statically. Javascript allows you to change structured HTML content dynamically.

There are many cases when you will just write and structure content in HTML. but if you need it to change due to user input or some other dynamic variable, you'll need to use javascript to update the HTML that is displayed to a user.

ian truong
ian truong
4,685 Points

thanks for the quick respond. i keep forgetting that JS makes the websites interactive cause by the user.