Home > Article > Web Front-end > JavaScript Learning Journey (2)_Basic Knowledge
Chapter 3 DOM
DOM is the acronym for "Document Object Model".
Node
Element node: It is the atom of DOM. For example: the name of the text paragraph element p, the name of the unordered list element ul... [The attribute value of nodeType is 1]
Text node (text node): Text nodes are always included inside element nodes. [The attribute value of nodeType is 3]
Attribute node: Attribute node is always placed in the start tag. For example: title="a gentle reminder" [the attribute value of nodeType is 2]
getElementById() method returns the object
document .getElementById(id) id must be placed in single quotes or double quotes. For example: document.getElementById("purchases")
The getElementsByTagName() method returns an object array
getElementsByTagName(tag) tag must be the name of the (x)html tag and placed in double quotes, such as: document.getElementsByTagName("li")
The getAttribute() method queries attributes through a specific object call
object.getAttribute(attribute)
setAttribute() method sets attributes
object.setAttribute(attribute,value)