Curriculum / Intermediate / Lesson 19

DOM: Updating Elements

textContent, innerHTML, classList β€” making a page interactive.

19 of 30
intermediate πŸ“– 6 min read 🎯 3 questions

Updating DOM Elements

Once you've selected an element, you can update its content, attributes, and styles to make your page interactive.

πŸ’‘ Key insight textContent is safer than innerHTML because it doesn't parse HTML β€” use textContent unless you specifically need HTML rendering.

Changing Content

Changing Attributes

Working with Classes

Common Mistakes

Quick Quiz

1. Which method is safer for setting plain text content?

2. How do you add a class to an element?

3. What does classList.toggle('active') do?

Summary

Back to curriculum