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
|
<!DOCTYPE html>
<title>Node.parentElement</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
test(function() {
assert_equals(document.parentElement, null)
}, "When the parent is null, parentElement should be null")
test(function() {
assert_equals(document.doctype.parentElement, null)
}, "When the parent is a document, parentElement should be null (doctype)")
test(function() {
assert_equals(document.documentElement.parentElement, null)
}, "When the parent is a document, parentElement should be null (element)")
test(function() {
var comment = document.appendChild(document.createComment("foo"))
assert_equals(comment.parentElement, null)
}, "When the parent is a document, parentElement should be null (comment)")
test(function() {
var df = document.createDocumentFragment()
assert_equals(df.parentElement, null)
var el = document.createElement("div")
assert_equals(el.parentElement, null)
df.appendChild(el)
assert_equals(el.parentNode, df)
assert_equals(el.parentElement, null)
}, "parentElement should return null for children of DocumentFragments (element)")
test(function() {
var df = document.createDocumentFragment()
assert_equals(df.parentElement, null)
var text = document.createTextNode("bar")
assert_equals(text.parentElement, null)
df.appendChild(text)
assert_equals(text.parentNode, df)
assert_equals(text.parentElement, null)
}, "parentElement should return null for children of DocumentFragments (text)")
test(function() {
var df = document.createDocumentFragment()
var parent = document.createElement("div")
df.appendChild(parent)
var el = document.createElement("div")
assert_equals(el.parentElement, null)
parent.appendChild(el)
assert_equals(el.parentElement, parent)
}, "parentElement should work correctly with DocumentFragments (element)")
test(function() {
var df = document.createDocumentFragment()
var parent = document.createElement("div")
df.appendChild(parent)
var text = document.createTextNode("bar")
assert_equals(text.parentElement, null)
parent.appendChild(text)
assert_equals(text.parentElement, parent)
}, "parentElement should work correctly with DocumentFragments (text)")
test(function() {
var parent = document.createElement("div")
var el = document.createElement("div")
assert_equals(el.parentElement, null)
parent.appendChild(el)
assert_equals(el.parentElement, parent)
}, "parentElement should work correctly in disconnected subtrees (element)")
test(function() {
var parent = document.createElement("div")
var text = document.createTextNode("bar")
assert_equals(text.parentElement, null)
parent.appendChild(text)
assert_equals(text.parentElement, parent)
}, "parentElement should work correctly in disconnected subtrees (text)")
test(function() {
var el = document.createElement("div")
assert_equals(el.parentElement, null)
document.body.appendChild(el)
assert_equals(el.parentElement, document.body)
}, "parentElement should work correctly in a document (element)")
test(function() {
var text = document.createElement("div")
assert_equals(text.parentElement, null)
document.body.appendChild(text)
assert_equals(text.parentElement, document.body)
}, "parentElement should work correctly in a document (text)")
</script>
|