Node.childElementCount

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

We’d love to hear your thoughts on the next set of proposals for the JavaScript language. You can find a description of the proposals here.
Please take two minutes to fill out our short survey.

Свойство Node.childElementCount предназначено только для чтения и возвращает число дочерних элементов узла.

Синтаксис

var elCount = Node.childElementCount;
  • elCount - целое число, количество дочерних элементов узла Node.
  • Node - объект, представляющий собой Document, DocumentFragment или Element.

Предупреждение: А наш добрый друг Internet Explorer в 6, 7 и 8 версиях ошибочно считает элементами комментарии в HTML-коде (Comment).

Пример

js
var foo = document.getElementById("foo");
if (foo.childElementCount > 0) {
  // здесь нужный код..
}

Спецификации

Specification
DOM
# dom-parentnode-childelementcount

Совместимость с браузерами