DOM query
Get the child nodes of an element node
- Called through specific element nodes
- getElementsByTagName( )
- Method, return the descendant node of the specified label name of the current node
- childNodes
- Attribute, which means all child nodes of the current node
- Will get all nodes including text nodes
- The whitespace between tags will also be treated as text nodes
- Note: In IE8 and below browsers, blank text will not be treated as a child node
- firstChild
- Attribute, which represents the first node of the current node
- lastChild
- Attribute, which represents the last node of the current node
- children
- Property, you can get all the child elements of the current element, excluding blank text nodes
- firstElementChild
- Property, you can get the first child element of the current element, excluding blank text nodes
- Does not support IE8 and below browsers
Get parent node and sibling node
Called through specific nodes
- parentNode
- Attribute, which represents the parent node of the current node
- previousSibling
- Attribute, representing the previous sibling node of the current node
- nextSibling
- Attribute, representing the next sibling node of the current node
- innerText
- Attribute, you can get the text content inside the element
- It is similar to innerHTML, the difference is that it will automatically remove html 5.previousElementSibling
- Attribute, representing the previous sibling element of the current element, not supported under IE8