14.2.2 common inclusion relationships between HTML elements
Some HTML elements can be nested with each other. For example, <div> elements can be nested with each other, while some HTML elements cannot
Nesting each other. For example, <TD> An element can only be a child element of <tr> elements, and <option> An element can only be used as <SELECT>
The child element of the element.
The HTML document also contains two object systems: Form objects and table objects.
Form objects can contain basic input objects, <SELECT> elements, and <SELECT> elements.
Contains multiple <option> elements.
A table object can contain the title (htmltablecaptionelement) Control and multiple tables.
A row (htmltablecolelement) space. Each table row can contain multiple cells (htmltablecellelement)
Control.
14.3 access HTML elements
To dynamically modify HTML elements, you must be able to access HTML elements. Dom provides two methods to access HTML elements.
Access HTML elements by ID.
Access HTML elements by using node relationships.
The previous method is easy to use, mainly including the getelementbyid () method provided by the document; the latter Method
The Tree nodes are accessed using the Parent-Child and sibling relationships.
14.3.1 access HTML elements by ID
The following method is used to access HTML elements by ID:
Document. getelementbyid (idval): returns the HTML element whose ID attribute value is idval in the document.
14.3.2 access HTML elements using node relationships
The attributes and methods for accessing HTML elements using node relationships are as follows:
Node parentnode: returns the parent node of the current node. Read-only attribute.
Node perviussibling: returns the previous sibling node of the current node. Read-only attribute.
Node nextsibling: returns the last sibling node of the current node. Read-only attribute.
Node [] childnodes: returns all child nodes of the current node. Read-only attribute.
Node [] getelementsbytagname (tagname): returns all child nodes of the current node with the specified tag name.
Node firstchild: returns the first subnode of the current node. Read-only attribute.
Node lastchild: returns the last child node of the current node. Read-only attribute.