Login Register Appointment

DOM Manipulation (Changing HTML with JS)

Lesson 15/17 | Study Time: 90 Min

What You Will Learn in This Live Session

1. Understanding the DOM

  • What is the Document Object Model (DOM)?
  • How the browser represents HTML as a tree-like structure.
  • Why JavaScript is used to modify the DOM dynamically.

2. Selecting HTML Elements with JavaScript

  • Different methods to select elements:
    • getElementById() – Select an element by its ID.
    • getElementsByClassName() – Select elements by class name.
    • getElementsByTagName() – Select elements by tag.
    • querySelector() and querySelectorAll() – More flexible element selection.

3. Modifying Elements in the DOM

  • Changing text content using .innerText and .innerHTML.
  • Modifying attributes (e.g., changing src for images, updating links).
  • Applying CSS styles dynamically with .style properties.

4. Creating and Removing Elements

  • Adding new elements using createElement() and appendChild().
  • Removing elements dynamically with removeChild() and .remove().

5. Event-Based DOM Manipulation

  • Updating the DOM in response to user actions (e.g., button clicks).
  • Handling events like click, input, and hover to modify HTML dynamically.