Before looking at the HTML node this thing these dumplings has been very vague, so on the internet to find a "DOM programming art" PDF document, the program tested the next
<body> <div id= "box" onclick= "Console.log (This)" > this here <span class=" 1234 ">here</span> where / var div = document.getElementById (' box '). Childnodes[1].childnodes[0].nodevalue; var div = document.getElementById (' box '). ChildNodes; Console.log (div); </script>
Run in Chrome
Showing 6 nodes, let's see what these 6 nodes are
- Text:this
- H2#wrap.123:here<span class= "1234" >here</span> where
- Text:that
As you can see, ChildNodes is the first generation of child nodes of the current element, and the order is composed of the following combinations of nodes
- Text
- Text element text
- text element text element text
When. Box is only pure in text, or empty, there will also be a text node, that is, the first case
When an element exists in. box, a text node exists before and after the element, regardless of whether text is empty or not, which is the second case
Then you can
ChildNodes Node properties in HTML