- The DOM (Document Object Model) is the browser's live, tree-shaped model of a web page. Change the DOM and the page updates instantly.
documentis the object at the top of the tree.- Select elements with
getElementById("id"),querySelector(selector)(first match) andquerySelectorAll(selector)(all matches, as a NodeList). - Selectors:
tag,.class,#id,parent child. No match givesnull. textContentchanges text safely.innerHTMLchanges HTML, but never use it with user input (XSS danger!).- Change styles with
element.style.propertyName(camelCase), or better, withclassList.add/remove/toggle/contains. - Attributes: properties like
src,href,value,checked, orgetAttribute/setAttribute. Custom data lives indata-*attributes anddataset. - Create elements with
document.createElement, add them withappend,prepend,beforeorafter, and remove them withremove(). - Data in, page out: build the page from arrays of objects using loops and functions.
Reading is step one
CurlyScript turns these notes into a game: short questions, an explanation after every answer, and a test at the end of each grade. Free, with nothing to sign up for.