blob: 35328313e6dd42997da9242f8223458906aea542 (
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
|
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CSS Selectors :last-of-type</title>
<link rel="help" href="https://drafts.csswg.org/selectors-4/#the-last-of-type-pseudo">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<!--
See also:
* child-indexed-pseudo-class.html
* child-indexed-no-parent.html
-->
<body>
<div>
<div id="target1">Whitespace nodes should be ignored.</div>
</div>
<div>
<div></div>
<div id="target2">Thre is another child element of the same type.</div>
</div>
<div>
<div id="target3">There is a posterior child element of another type.</div>
<blockquote></blockquote>
</div>
<div>
<blockquote>
<div id="target4">A next element of the parent should not affect.</div>
</blockquote>
<div></div>
</div>
<div>
<div>
<div id="target5">The parent element of the same type should not affect.</div>
</div>
</div>
<div>
<div id="target6">A child of the next element should not affect.</div>
<blockquote>
<div></div>
</blockquote>
</div>
<div>
<div id="target7" data-expected="false">The first child element of the same
type should not match.</div>
<div></div>
</div>
<div>
<div id="target8" data-expected="false">The first child element of the same
type should not match, the last child has a case-different tag name.</div>
<DIV></DIV>
</div>
<div>
<div id="insertAfter1"></div>
</div>
<script>
for (let i = 1; i <= 8; ++i) {
let target = document.querySelector(`#target${i}`);
test(() => {
if (target.dataset.expected == 'false')
assert_false(target.matches('div:last-of-type'));
else
assert_true(target.matches('div:last-of-type'));
}, target.textContent.replaceAll('\n', ' '));
}
test(() => {
const ia1 = document.querySelector('#insertAfter1');
const target = document.createElement('div');
assert_true(ia1.matches('div:last-of-type'));
ia1.parentNode.insertBefore(target, ia1.nextSibling);
assert_true(target.matches('div:last-of-type'));
assert_false(ia1.matches('div:last-of-type'));
target.remove();
assert_true(ia1.matches('div:last-of-type'));
}, 'Dynamic insertion and removal');
</script>
|