For DOM elements, children refers to the DOM object type's child object, excluding the invisible textnode between the tags, and childnodes includes Textnode objects that are invisible between the tags.
For a specific look at the children and childnodes in the chrome environment test:
1, 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
<! DOCTYPE html> |
The test results are as follows:
1 2 3 4 5 6 7 |
Div1.children Run Result: span div1.childnodes run result: undefined span undefined |
There are two undefined nodes in the result of the childnodes set above, which is the textnode of nodetype=3.
If you write HTML code as follows, the results of children and childnodes are no different.
1 2 3 |
<body> <div id= "div1" class= "div" ><span id= "S1" class= "sp" lang= "ZH-CN" ></span></div> </body> |
No other differences were found in the measurement of HTML elements such as document, head, body, and Div