Find out if an <ul> element has any child nodes:
The result of list will be:
More "Try it Yourself" examples below.
The hasChildNodes() method returns true if the specified node has any child nodes, otherwise false.
Note: Whitespace inside a node is considered as text nodes, so if you leave any white space or line feeds inside an element, that element still has child nodes.
Method | |||||
---|---|---|---|---|---|
hasChildNodes() | Yes | Yes | Yes | Yes | Yes |
None |
Return Value: | A Boolean, returns true if the node has child nodes, false otherwise |
---|---|
DOM Version | Core Level 1 Node Object |
Remove the first child node (index 0) inside an <ul> element, if the element has any child nodes:
HTML DOM reference: element.childNodes() Method
HTML DOM reference: node.firstChild Property
HTML DOM reference: node.lastChild Property
HTML DOM reference: node.parentNode Property
HTML DOM reference: node.nextSibling Property
HTML DOM reference: node.previousSibling Property