Change structure and presentation: textContent, innerHTML (careful with XSS), classList, and createElement.
Safe text
Prefer textContent for user-visible strings—innerHTML parses HTML and can execute scripts if data is untrusted. See XSS lesson.
classList
el.classList.add('active') — toggles pair with CSS from the CSS track.
Important interview questions and answers
- Q: textContent vs innerHTML?
A: textContent escapes; innerHTML interprets tags. - Q: createElement workflow?
A: Create node, set properties, append to parent.
Self-check
- Why avoid innerHTML with user input?
- What does classList.toggle do?
Pitfall: innerHTML with user input enables XSS—use textContent.
Interview prep
- textContent vs innerHTML?
textContent is safe for plain text; innerHTML parses HTML.