Objects group together a set of variables and functions to create a model of a something you would recognize from the real world. In an object, variables and functions take on new names.
- you access the properties or methods of an object using dot natation.
- you can also access properties using square brackets.
Accessing and updating the DOM tree involves two steps:
-
Locate the node that represents the element you want to work with.
-
Use its text content, child elements, and attributes.
-
STEP 1: ACCESS THE ELEMENTS
- SELECT AN INDIVIDUAL ELEMENT NODE
- SELECT MULTIPLE ELEMENTS (NODELISTS)
- TRAVERSING BETWEEN ELEMENT NODES
- WORK WITH THOSE ELEMENTS
- ACCESS/ UPDATE TEXT NODES
- WORK W ITH HTML CONTENT
- ACCESS OR UPDATE ATTRIBUTE VALUES
- SELECTING ELEMENTS USING ID ATTRIBUTES
- SELECTING ELEMENTS USING class ATTRIBUTES
- SELECTING ELEMENTS BY TAG NAME
- SELECTING ELEMENTS USING CSS SELECTORS
- parentNode
- previousSibling nextSibling
- firstChild and lastChild
When you select a text node, you can retrieve or amend the content of it using the node Va 1 ue property
Using the i nnerHTML property, you can access and amend the contents of an element,including any child elements.
- CREATE THE ELEMENT
- GIVE IT CONTENT
- ADD IT TO THE DOM
- STORE THE ELEMENT TO BE REMOVED IN A VARIABLE
- STORE THE PARENT OF THAT ELEMENT IN A VARIABLE
- REMOVE THE ELEMENT FROM ITS CONTA INING ELEMENT
- document.write()
- element.innerHTML