-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContainsExample02.htm
executable file
·39 lines (33 loc) · 1.19 KB
/
ContainsExample02.htm
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
<!DOCTYPE html>
<html>
<head>
<title>Contains Example 2</title>
<script type="text/javascript" src="client.js"></script>
</head>
<body>
<input type="button" value="Does html contain body?" onclick="getContains()">
<script type="text/javascript">
function contains(refNode, otherNode){
if (typeof refNode.contains == "function" &&
(!client.engine.webkit || client.engine.webkit >= 522)){
return refNode.contains(otherNode);
} else if (typeof refNode.compareDocumentPosition == "function"){
return !!(refNode.compareDocumentPosition(otherNode) & 16);
} else {
var node = otherNode.parentNode;
do {
if (node === refNode){
return true;
} else {
node = node.parentNode;
}
} while (node !== null);
return false;
}
}
function getContains(){
alert(contains(document.documentElement, document.body));
}
</script>
</body>
</html>