Node type
- Element node
- Attribute node
- Text node
Element node attributes
- innerNodes gets the content in the tag, which will be parsed into tags
- innerText gets the plain text between the tags, does not parse the tags, sets the plain text
- 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