Common methods and attributes of DOM query

DOM query

Get the child nodes of an element node

  • Called through specific element nodes
  1. getElementsByTagName( )
  • Method, return the descendant node of the specified label name of the current node
  1. 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
  1. firstChild
  • Attribute, which represents the first node of the current node
  1. lastChild
  • Attribute, which represents the last node of the current node
  1. children
  • Property, you can get all the child elements of the current element, excluding blank text nodes
  1. 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

  1. parentNode
  • Attribute, which represents the parent node of the current node
  1. previousSibling
  • Attribute, representing the previous sibling node of the current node
  1. nextSibling
  • Attribute, representing the next sibling node of the current node
  1. 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

Guess you like

Origin blog.csdn.net/weixin_48769418/article/details/113979720
Recommended