blob: 04e40dbdae466cc315de2faf4b8b1a5645888956 (
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
|
---
title: Node.contains()
slug: Web/API/Node/contains
translation_of: Web/API/Node/contains
---
<div>{{APIRef("DOM")}}</div>
<p><strong><code>Node.contains()</code></strong> 메소드는 주어진 인자가 node 의 자손인지, 아닌지에 대한 {{jsxref("Boolean")}} 값을 리턴합니다.</p>
<h2 id="Syntax">Syntax</h2>
<pre class="syntaxbox">node.contains( otherNode )
</pre>
<h2 id="Example">Example</h2>
<p>이 함수는 요소가 페이지의 body 안에 있는지 검사합니다. <code>contains</code> 는 포괄적이므로 node 가 body 자기 자신일 경우에도 <font face="consolas, Liberation Mono, courier, monospace"><span style="background-color: rgba(220, 220, 220, 0.5);">true</span></font> 가 반환됩니다. 만약 이걸 원하지 않는 경우에는 node 가 body 자기 자신인지 검사하여 <code>false</code> 를 반환하여 버리면 됩니다.</p>
<pre class="brush:js">function isInPage(node) {
return (node === document.body) ? false : document.body.contains(node);
}</pre>
<h2 id="Specifications" name="Specifications">Specifications</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName("DOM WHATWG", "#dom-node-contains", "Node.contains()")}}</td>
<td>{{Spec2("DOM WHATWG")}}</td>
<td>Initial definition</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{Compat("api.Node.contains")}}</p>
<h2 id="See_also">See also</h2>
<ul>
<li>{{domxref("Node.compareDocumentPosition")}}</li>
<li>{{domxref("Node.hasChildNodes")}}</li>
</ul>
|