How to use JavaScript Dom Node hasChildNodes

In this article I have described about Dom Node hasChildNodes() method in JavaScript.
  • 2361

JavaScript Dom Node hasChildNodes() method

  • As we already know that node object is used to represent and add node within the HTML document.
  • The hasChildNodes() method checks whether any node has any child node or not and return boolean value.
  • It returns true if there is any child node otherwise false.

Browser support

Following are the main browsers which support the hasChildNodes() method of Dom Node object

  • Internet Explorer.
  • Firefox.
  • Opera.
  • Google Chrome.
  • Safari.


The hasChildNodes() of Dom Node object has following syntax


Lets take an example

<!DOCTYPE html>



<p id="menu">Display Color</p>

<button onclick="myFunction()">Try it</button>

<script type="text/javascript">

    Boolean.prototype.Blcolor = function () {

        if (this.valueOf() == true) {

            this.color = "YELLOW";




            this.color = "RED";




    function myFunction() {

        var a = new Boolean(1);


        var x = document.getElementById("menu");

        x.innerHTML = a.color;







dn child1.jpg

When we click on button

dn child2.jpg

Further Readings

You may also want to read these related articles :here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2020 DotNetHeaven. All rights reserved.