ParentNode.childElementCount
읽기 전용 속성은 주어진 요소의 자식 요소 개수를 unsigned long
타입으로 반환합니다.
이 속성은 처음에 ElementTraversal
인터페이스에 정의되었습니다. 이 인터페이스는 자식이 있는 Node
와 자식 Node
를 위한 두 가지 고유한 속성 집합을 포함하고 있었는데, 각각 ParentNode
와 ChildNode
개별 인터페이스로 이동되었습니다. childElementCount
의 경우 ParentNode
로 이동했습니다. 이것은 기술적인 변화로 호환성에는 영향을 미치지 않습니다.
문법
var count = node.childElementCount;
count
unsigned long
(정수) 타입의 반환값.node
Document
,DocumentFragment
또는Element
객체.
예제
var foo = document.getElementById('foo');
if (foo.childElementCount > 0) {
// Do something
}
폴리필 (IE8 & IE9 & Safari)
이 속성은 IE9 이전 버전에서는 지원하지 않습니다. IE9과 Safari는 Document
와 DocumentFragment
객체에서 이 속성을 지원하지 않습니다.
;(function(constructor) {
if (constructor &&
constructor.prototype &&
constructor.prototype.childElementCount == null) {
Object.defineProperty(constructor.prototype, 'childElementCount', {
get: function() {
var i = 0, count = 0, node, nodes = this.childNodes;
while (node = nodes[i++]) {
if (node.nodeType === 1) count++;
}
return count;
}
});
}
})(window.Node || window.Element);
명세
표준 | 상태 | 비고 |
---|---|---|
DOM The definition of 'ParentNode.childElementCount' in that specification. |
Living Standard | Split the ElementTraversal interface in ChildNode and ParentNode . This method is now defined on the latter.The Document and DocumentFragment implemented the new interfaces. |
Element Traversal Specification The definition of 'ElementTraversal.childElementCount' in that specification. |
Obsolete | Added its initial definition to the ElementTraversal pure interface and use it on Element . |
브라우저 호환성
BCD tables only load in the browser
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
참조
ParentNode
와ChildNode
인터페이스.