W3Teacher
  • Explore
    Browse by field
    Artificial Intelligence Accounting & Finance Information Technology
    Show all fields
  • Interview Q&A
    • All Interview Questions
    • Beginner
    • Intermediate
    • Advanced
  • Practice
    • MCQs
    • Quizzes
    • Mock Interviews
  • About
  • Sign in
  • Get Started
  1. Home
  2. Search: CSRF & Content Security Policy
  3. JavaScript
  4. DOM & Events
  5. Question
All 10 DOM & Events questions
More in DOM & Events
What is event bubbling? What does event.preventDefault() do? What is event delegation and why is it a performance best practice? What's the difference between event.target and event.currentTarget? How do you create and dispatch a custom DOM event? What's the difference between the capturing and bubbling phases of event propagation? How do you properly clean up event listeners to avoid memory leaks? What is the difference between passive and non-passive event listeners for scroll performance? How does MutationObserver let you react to DOM changes made by other code?
Advertisement
Back to results for “CSRF & Content Security Policy”
JavaScript › DOM & Events

How do you select and modify an element's text content?

Beginner

Answer

Use document.querySelector() (or similar) to find the element, then set its textContent property to update the text safely without interpreting it as HTML.
const el = document.querySelector('#status');
el.textContent = 'Saved successfully';
Real-world example Updating a status message on screen after a save action completes.

Common follow-ups: What's the security risk of using innerHTML instead of textContent with user input?

Security: XSS CSRF & Content Security Policy
Previous question What does event.preventDefault() do? Next question What is event delegation and why is it a performance best practice?
All 10 DOM & Events questions
W3Teacher

Learn technologies. Ace technical interviews.


    Learn
    • Technologies
    • Tutorials
    • Interview Questions
    • MCQs
    Practice
    • Quizzes
    • Mock Interviews
    • Bookmarks
    • Dashboard
    Get the latest questions & tips

    Fresh interview questions and practice tips, straight to your inbox.

    Company
    • About
    • Contact us
    • Privacy Policy
    • Terms & Conditions

    © 2026 W3Teacher. All rights reserved.