JSJavaScript · Lesson 11 of 14
DOM & Events
The DOM is the browser API that lets JavaScript interact with HTML. It is a tree of nodes. You can read it, modify it, and listen for events on it. This is how every interactive web page works.
The Document Object Model represents the HTML structure as a tree of JavaScript objects. document.querySelector gives you the first matching element; document.querySelectorAll gives you a NodeList of all matches. Always wait for DOMContentLoaded before querying elements.
◆ Note
Never use innerHTML with user-provided content — it executes scripts and enables XSS attacks. Use textContent for plain text, or create elements with createElement and textContent for safe HTML construction.
Never use innerHTML with user-provided content — it executes scripts and enables XSS attacks. Use textContent for plain text, or create elements with createElement and textContent for safe HTML construction.