JavaScript hasChildNodes() Method Tutorial

In this section, we will learn what the Element hasChildNodes() method is and how to use it in JavaScript.

What is Element hasChildNodes() Method in JavaScript?

The JavaScript Element hasChildNodes() method is used to check and see if an element in an HTML document has any child of any type (Element-node, Text-node, Comment-node).

Element hasChildNodes() Method Syntax:

element.hasChildNodes();

Element hasChildNodes() Method Parameter

The method does not take an argument.

Element hasChildNodes() Method Return Value

The return value of this method is of type boolean and will be equal to true if the target element has a child or false if the element didn’t have any.

Example: using hasChildNodes() method in JavaScript

See the Pen using hasChildNodes() method in JavaScript by Omid Dehghan (@odchan1) on CodePen.

Leave a Reply