JavaScript JavaScript and the DOM 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,373 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.