DOM Manipulation
Essential DOM manipulation techniques with vanilla JavaScript
Table of Contents
Element Selection
Query Selectors
Select elements using CSS selectors for flexible element targeting
Get Element Methods
Traditional DOM methods for selecting elements by ID, class, or tag
Creating Elements
createElement & cloneNode
Create new elements or clone existing ones programmatically
innerHTML & insertAdjacentHTML
Insert HTML content directly into elements using string templates
Modifying Elements
Text & HTML Content
Modify the text and HTML content of elements safely
Attributes & Properties
Get, set, and remove HTML attributes and DOM properties
Styling & Classes
classList Methods
Manage CSS classes on elements with the classList API
Inline Styles
Directly manipulate element styles through the style property
DOM Traversal
Parent & Child Navigation
Navigate between parent and child elements in the DOM tree
Sibling Navigation
Navigate between sibling elements at the same DOM level
Adding & Removing
Adding Elements
Add elements to the DOM using various insertion methods
Removing Elements
Remove elements from the DOM or replace them with new ones
Events - Basics
Event Listeners
Attach and remove event handlers to respond to user interactions
Event Object
Access event properties and control event behavior
Events - Advanced
Event Delegation
Handle events efficiently using event bubbling and delegation
Custom Events
Create and dispatch custom events for component communication
Forms
Form Elements & Data
Access and manipulate form elements and their values
Form Events
Handle form-specific events for validation and interaction
Modern DOM APIs
Intersection Observer
Efficiently detect when elements enter or leave the viewport
Mutation Observer
Watch for changes to the DOM tree and element attributes