Chapter 8. DOM
JavaScript allows you to restructure an HTML document, for instance by adding, removing, or reordering the items shown on the page. In fact, without the possibility of restructuring the document, or at the very least providing some feedback (such as text in a form field or an image swap), JavaScript is pretty much worthless.
The example script that best demonstrates this restructuring is Sandwich Picker. Users can quickly and easily specify the sandwiches they want to order, and the script gathers the data by moving the <tr>s that contain sandwiches to the order table—in other words, by changing the document structure.
To change anything on a page, JavaScript needs access to all elements in the HTML document. Allowing this access ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access