Get child element nodes (children, childNodes), childrenchildnodes
Methods for Retrieving Element nodes in js that have DOM, such as getElementsByTagName .. There is another way to obtain child elements: ChildNodes
However, ChidNodes is "not normal" in the advanced browser except (IE6-8), because it not only obtains the element node but also obtains the text node, this is the legendary buy one get one free? However, the one-to-one activity can be used with nodeType when we don't want it. The Code is as follows:
Of course, this judgment is for advanced browsers. IE6-8 is not to judge nodeType, because it was originally obtained only element nodes, no text nodes.
In addition to the childNodes method to obtain sub-elements, there is also a method called children, this is not to judge the compatibility, IE6-8, other advanced browsers support. The usage is as follows:
Let's talk about the methods for obtaining these two nodes: firstChild (firstElementChild) [first child element], lastChild (lastElementChild) [last child element], nextSibling (nextElementSibling) [Next element of the same level], previousSibling (previousElementSibling) [previous element of the same level], parentNode [parent node]
Among them, the brackets are in the advanced browser to get the Element Node Method, inside the brackets (IE6-8) and inside the brackets (advanced browser) is equivalent to solving a compatibility problem. I will not give an example.