Like ParentNode and parentelement functions,childnodes and children function as well. But parentnode and childnodes are consistent with the standard of the Global Consortium, which can be said to be more generic. While the other two are only IE support, not the standard, Firefox does not support
Example:
"ParentNode" is often used to get the parent node of an element. The Parentnodes is understood as a container with a child node in the container, as follows:
<div id= "Parent" >
<b id= "Child" >my text</b>
</div>
In the above code, you see "Dad" as a div container, the container has a "child", is the bold text part. If you're going to use the getElementById () method to get a bold element and want to know who the "Daddy" is, the information returned will be a Div. The following script is shown:
<script type= "Text/javascript" >
<!--
alert (document.getElementById "Child"). Parentnode.nodename );
-->
</script>
With ParentNode not only find a "dad", "son" can also become "Dad", as the following example ...
<div id= "Parent" >
<div id= "childparent" >
<b id= "Child" >my text</b>
</div >
</div>
There are two "daddies" and two "children" in this code. The first Div (id "parent") is the "father" of the second Div (childparent). There is a bold element (id "child") in "Childparent", which is the "kid" of the "childparent" div. So, how to access to "Grandpa" (id "parent")? as follows:
<script type= "Text/javascript" >
<!--
alert (document.getElementById ("Child"). ParentNode.parentNode.nodeName);
-->
</script>
Did you notice that two parentnode were used? "Parentnode.parentnode". The first parentnode is the div (id "childparent"), because we want to get the outermost parent element, so another parentnode is added to the DIV (id "parent").
Using ParentNode not only finds an element's nodename, but more. For example, you can get the parent node that contains a large number of elements and add a new node at the end. IE has its own name called "Parentelement", which is recommended for cross browser scripting ParentNode
The above is a simple discussion of the HTML elements of the parent node, the child node is a small series to share all the content, I hope to give you a reference, but also hope that we support the cloud habitat community.