Interacting with the page.
WHAT IT IS
The browser's representation of the document, as a structure code can read and change.
WHAT YOU CAN DO
Find elements Read and change their content Change their attributes and classes Add and remove elements Respond to events
WHAT TO PREFER FOR CHANGING APPEARANCE
Adding and removing classes, rather than setting styles directly.
WHY
It keeps presentation in the stylesheet, where it belongs.
WHAT TO BE CAREFUL WITH
Inserting content as markup, which allows injection if the content came from outside.
WHAT TO USE INSTEAD FOR TEXT
The property that sets text rather than markup.
WHY
It cannot be interpreted as elements.
WHAT MAKES DOM WORK SLOW
Repeatedly reading and changing the document Changes forcing the browser to recalculate layout Doing it inside a loop
WHAT TO DO ABOUT IT
Batch changes Build structures before inserting them Read all values before writing any
WHAT TO AVOID
Depending on document structure that may change.