aboutsummaryrefslogtreecommitdiff
path: root/files/ko/web/api/parentnode/childelementcount/index.html
blob: 665c417512e1ffa34aa904f56d6b34511f4564ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
---
title: ParentNode.childElementCount
slug: Web/API/ParentNode/childElementCount
tags:
  - API
  - DOM
  - ParentNode
  - Property
  - Reference
translation_of: Web/API/ParentNode/childElementCount
---
<div>{{ APIRef("DOM") }}</div>

<p><code><strong>ParentNode.childElementCount</strong></code> 읽기 전용 속성은 주어진 요소의 자식 요소 개수를 <code>unsigned long</code> 타입으로 반환합니다.</p>

<div class="note">
<p>이 속성은 처음에 {{domxref("ElementTraversal")}} 인터페이스에 정의되었습니다. 이 인터페이스는 자식이 있는 {{domxref("Node")}}와 자식 {{domxref("Node")}}를 위한 두 가지 고유한 속성 집합을 포함하고 있었는데, 각각 {{domxref("ParentNode")}}와 {{domxref("ChildNode")}} 개별 인터페이스로 이동되었습니다. <code>childElementCount</code>의 경우 {{domxref("ParentNode")}}로 이동했습니다. 이것은 기술적인 변화로 호환성에는 영향을 미치지 않습니다.</p>
</div>

<h2 id="문법">문법</h2>

<pre class="syntaxbox notranslate">var <var>count</var> = <em>node</em>.childElementCount;
</pre>

<dl>
 <dt><code>count</code></dt>
 <dd><code>unsigned long</code>(정수) 타입의 반환값.</dd>
 <dt><code>node</code></dt>
 <dd>{{domxref("Document")}}, {{domxref("DocumentFragment")}} 또는 {{domxref("Element")}} 객체.</dd>
</dl>

<h2 id="예제">예제</h2>

<pre class="brush:js notranslate">var foo = document.getElementById('foo');
if (foo.childElementCount &gt; 0) {
  // Do something
}
</pre>

<h2 id="폴리필_IE8_IE9_Safari">폴리필 (IE8 &amp; IE9 &amp; Safari)</h2>

<p>이 속성은 IE9 이전 버전에서는 지원하지 않습니다. IE9과 Safari는 <code>Document</code>와 <code>DocumentFragment</code> 객체에서 이 속성을 지원하지 않습니다.</p>

<pre class="brush:js notranslate">;(function(constructor) {
  if (constructor &amp;&amp;
      constructor.prototype &amp;&amp;
      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);
</pre>

<h2 id="명세">명세</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">표준</th>
   <th scope="col">상태</th>
   <th scope="col">비고</th>
  </tr>
  <tr>
   <td>{{SpecName('DOM WHATWG', '#dom-parentnode-childelementcount', 'ParentNode.childElementCount')}}</td>
   <td>{{Spec2('DOM WHATWG')}}</td>
   <td>Split the <code>ElementTraversal</code> interface in {{domxref("ChildNode")}} and <code>ParentNode</code>. This method is now defined on the latter.<br>
    The {{domxref("Document")}} and {{domxref("DocumentFragment")}} implemented the new interfaces.</td>
  </tr>
  <tr>
   <td>{{SpecName('Element Traversal', '#attribute-childElementCount', 'ElementTraversal.childElementCount')}}</td>
   <td>{{Spec2('Element Traversal')}}</td>
   <td>Added its initial definition to the <code>ElementTraversal</code> pure interface and use it on {{domxref("Element")}}.</td>
  </tr>
 </tbody>
</table>

<h2 id="브라우저_호환성">브라우저 호환성</h2>



<p>{{Compat("api.ParentNode.childElementCount")}}</p>

<h2 id="참조">참조</h2>

<ul>
 <li>{{domxref("ParentNode")}}와 {{domxref("ChildNode")}} 인터페이스.</li>
 <li>
  <div class="syntaxbox">이 인터페이스를 구현한 객체 타입: {{domxref("Document")}}, {{domxref("Element")}}{{domxref("DocumentFragment")}}.</div>
 </li>
</ul>