Table of contents

  1. 1. Summary
  2. 2. Syntax
  3. 3. Examples
  4. 4. Specification
Table of contents
  1. 1. Summary
  2. 2. Syntax
  3. 3. Examples
  4. 4. Specification

« Gecko DOM Reference

Summary

hasChildNodes returns a Boolean value indicating whether the current element has child nodes or not.

Syntax

element.hasChildNodes()

Examples

var result = element.hasChildNodes();

Next example removes the first child node inside the element with the id "foo" if foo has child nodes

var foo = document.getElementById("foo")
if (foo.hasChildNodes()) { 
  foo.removeChild(foo.childNodes[0]);
}

Note that element.hasChildNodes, without the parenthesises, will return the hasChildNodes Function, and not a Boolean.

Specification

hasChildNodes

Tags (3)

Edit tags

Attachments (0)

 

Attach file