2020/4/19 element node

Node type

  1. Element node
  2. Attribute node
  3. Text node



Element node attributes

  1. innerNodes gets the content in the tag, which will be parsed into tags
  2. innerText gets the plain text between the tags, does not parse the tags, sets the plain text
  3. outerHTML will be parsed from the start of the outer tag to the end of the outer tag



Get child nodes

childNodes access all the child nodes under the current node
firstChild access the first
bit in the child node lastChild access the last bit in the
child node nextSibling access the next bit in the
current node sibling node previousSibling access the previous bit in the current node sibling node
[Note] the above The attributes all contain text nodes (space returns and line feeds)


children access all child nodes under the current node
firstElementChild access the first
bit in the child node lastElementChild access the last bit in the child node
nextElementSibling access the next bit in the
current node sibling node previousElementSibling access the previous bit in the current node sibling node
[Note] the above The method only gets the child nodes, element nodes

  <script type="text/javascript">
   window.onload = function(){
    var huoqu = document.getElementById("jiedian");
    alert(huoqu.childNodes.length);
    alert(huoqu.childNodes[0].nodeType);
   }
  </script>
  
   <body>
   <div id=jiedian><em>em文本</em>div文本<strong>strong文本</strong></div>
   </body>

return value

nodeType nodeName nodeValue
Element node 1 Label name null
Attribute node 2 Attribute name Attribute value
Text node 3 #text Text content

attributes, get all element nodes on the current element node

Published 2 original articles · liked 0 · visits 23

Guess you like

Origin blog.csdn.net/qq1547511739/article/details/105611935