Node.contains()
Node.contains()
메소드는 주어진 인자가 node 의 자손인지, 아닌지에 대한 Boolean
값을 리턴합니다.
Syntax
node.contains( otherNode )
Example
이 함수는 요소가 페이지의 body 안에 있는지 검사합니다. contains
는 포괄적이므로 node 가 body 자기 자신일 경우에도 true 가 반환됩니다. 만약 이걸 원하지 않는 경우에는 node 가 body 자기 자신인지 검사하여 false
를 반환하여 버리면 됩니다.
function isInPage(node) {
return (node === document.body) ? false : document.body.contains(node);
}
Specifications
Specification | Status | Comment |
---|---|---|
DOM The definition of 'Node.contains()' in that specification. |
Living Standard | Initial definition |
Browser compatibility
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help!
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | 9.0 (9.0) | 5.0[1] | (Yes) | 3.0[2] |
Feature | Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | ? | (Yes) | 9.0 (9.0) | ? | ? | ? |
[1] Internet Explorer only supports contains()
for elements.
[2] Safari 2.x implemented contains()
incorrectly.