DOCUMENT OBJECT MODEL
Main Structures, Methods, and Functionalities of the DOM

The scripts for these examples can be found in Book 2 of the *Programming Step-by-Step and More* guide.

Books 1 and 2 are available for purchase on Amazon.

10 DOM. (DOCUMENT OBJECT MODEL)

10.1 – Introduction to the DOM. Learning to select, modify, and manipulate DOM elements

I am the first element with class="item"

10.1.1 Selectors with class='lista'

Replace the content of the selector with id=titulo

Modify the text of an element. Replace with...

10.2.2a – Modify the src attribute that loads an image.

Change the attribute of an element. Replace one image with another

amazon
10.2.2b – Paint the background blue for all "article" elements

10.2.4 Remove Elements from the DOM

10.2.4.1 Empty all content inside the div

First paragraph

Second paragraph

Third paragraph

Fourth paragraph

10.2.4.2 Partially empty the content inside the div. Remove the third paragraph

First paragraph

Second paragraph

Third paragraph

Fourth paragraph

Next divisions created with createDocumentFragment()

Hierarchical Structure of the DOM

10.6 Selection Methods

Example getElementsByTagName

10.6.1 – Changing the text color of the content

This is the 1st paragraph inside 
|pre| tags
This paragraph with |pre| tags 
is inside a division.
This is the 3rd paragraph inside 
|pre| tags.

10.7 Modern Selection Methods

10.7.1 Methods querySelector and querySelectorAll

10.7.2 Advantages of querySelector and querySelectorAll

Example 1. Comparing both methods

This is a paragraph with class highlight

Another paragraph without the highlight class.

This is a span with class highlight.

10.8 Content Modification.

Example 1. Using the textContent property

Original text

Example 2. Using the innerText property

Original text

Example 3. Using the innerHTML property

Original text

10.9 Create and add new elements (createElement, appendChild, insertBefore)

10.9.1 and 10.9.2 Use of createElement and appendChild

This is the first paragraph inside the div with id="miContenedor"

10.9.3 Use of insertBefore

First text inside a p tag

Reference text

10.9.4 Combined use of createElement, appendChild, and insertBefore.

This is the original paragraph for exercise 10.9.4

10.10 Attribute Manipulation. Methods getAttribute, setAttribute, removeAttribute.

10.10.1 Use of getAttribute

Example 1. Get the value of the "href" attribute from a link

Visit an_example.com

Example 2. Get the value of a custom attribute.

Example 3. Form validation and data retrieval

10.10.2 Use of setAttribute

Example 1. Change the value of an existing attribute. Redirects the page

Visit example2.com

Example 2. Add a custom attribute

This is a div from Example 2 of section 10.10.2

Example 3. Change a CSS class

This is a paragraph with the class sencilla

Example 4. Create an element and assign attributes

10.10.3 Use of removeAttribute

Example 1. Remove Style attributes (style)

This is a red paragraph whose style will be removed

Example 2. Disable link functionality

This link will not go anywhere

Example 3. Disable a button

Reload the page to restart the process and repeat the test

Example 4. Enable attributes in a previously disabled form field.

Example 5. Remove attributes. Clear custom data from an element

Element content

Example 6. Remove Accessibility Attributes (aria-attributes)