Method ya HTML DOM Element hasChildNodes()
- Previous page hasAttributes()
- Next page id
- Go to the previous level Mwongozo wa DOM Elements
Muundo na Matumizi
Kamaanisha inaangalia ukichukua vifaa vya mwanafunzi yoyote,hasChildNodes()
The method returns true
, otherwise returns false
.
hasChildNodes()
The method is read-only.
Note
Whitespace between nodes is considered child nodes (text nodes).
See also:
HTML node and element
In HTML DOM(Document Object Model) in, HTML document is a collection of nodes that have (or do not have) child nodes.
NodeRefers to element nodes, text nodes, and comment nodes.
ElementWhitespace between them is also a text node.
And elements are just element nodes.
Child nodes and child elements
childNodes ReturnsChild nodesElement nodes, text nodes, and comment nodes).
children ReturnsChild elementsInstead of text and comment nodes).
Siblings and element siblings
SiblingsAre 'brothers' and 'sisters'.
SiblingsAre nodes that have the same parent node (in the same childNodes List).
Element siblingsAre elements that have the same parent element (in the same children List).
Example
Example 1
Does the element have child nodes:
let answer = element.hasChildNodes();
Example 2
Remove the first child node of the element:
if (element.hasChildNodes()) { element.removeChild(element.childNodes[0]); }
Syntax
element.hasChildNodes()
Parameter
None.
Return value
Type | Description |
---|---|
Boolean value | If the node has child nodes, it returns boolean true, otherwise it returns false. |
Browser support
element.hasChildNodes()
Is DOM Level 1 (1998) feature.
All browsers fully support it:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Support | 9-11 | Support | Support | Support | Support |
- Previous page hasAttributes()
- Next page id
- Go to the previous level Mwongozo wa DOM Elements