parentNode and parentElement function are the same.childrenNodes and childrenThe function is the same. butparentNode and childNodesIt complies with W3C standards and can be said to be relatively general. The other two are only supported by IE, not standard, and Firefox does not support it
Example:
"parentNode" is often used to obtain the parent node of a certain element. Understand parentNodes as a container, and there is a child node in the container, as follows:
<div > <b >My text</b> </div>
In the above code, you see that "Daddy" is used as a div container, which has a "child" in the container, which is the bold text part. If you plan to use the getElementById() method to get the bold element and want to know who "Daddy" is, the information returned will be a div. The following script is demonstrated as follows:
<script type="text/javascript"> <!-- alert("child").); //--> </script>
Using parentNode does not necessarily mean that only one "father" is found, "son" can also become "father", as in the following example...
<div > <div > <b >My text</b> </div> </div>
There are two "dads" and two "children" in the above code. The first div (id "parent") is the "dad" of the second div (childparent). There is a bold element (id "child") in "childparent" which is the "child" of the "childparent" div. So, how to access "grandfather" (id "parent")? As follows:
<script type="text/javascript"> <!-- alert(("child").); //--> </script>
Have you noticed that the two parentNodes are used in conjunction? "". The first parentNode is a div (id "childparent"). Because we want to get the outermost parent element, we add another parentNode and then we will reach the div (id "parent").
Using parentNode not only finds the nodeName of an element, but also more. For example, you can get the parent node with a large number of elements and add a new node at the end. IE has its own name called "parentElement", and it is recommended to use parentNode for cross-browser scripts
The above article briefly talks about the parent node and child node of the html element of js. This is all the content I share with you. I hope you can give you a reference and I hope you can support me more.