blob: 720db87af7e76cdaa9258680ca5b3f7d6075e07a (
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
|
<html>
<head>
<script>
function debug(str) {
console = document.getElementById('console');
li = document.createElement('li');
console.appendChild(li);
li.appendChild(document.createTextNode(str));
}
function runTests() {
if (window.testRunner) {
testRunner.dumpAsText();
}
div = document.getElementById('duplicate');
dup1 = div.parentNode.removeChild(div);
div = document.getElementById('duplicate');
if (!div) {
debug('Failed: getElementById returned null');
return;
}
if (div.firstChild.nodeValue != 'This is the second duplicate div') {
debug('Failed: getElementById returned the wrong div');
return;
}
dup2 = div.parentNode.removeChild(div);
if (document.getElementById('duplicate')) {
debug('Failed: getElementById did not return null');
return;
}
// Now insert the nodes again
container = document.getElementById('container');
container.appendChild(dup1);
container.appendChild(dup2);
if (!document.getElementById('duplicate')) {
debug('Failed: getElementById returned null');
return;
}
debug('Success!');
}
</script>
</head>
<body onLoad="runTests()">
This tests that getElementById works as elements with duplicate ids are added and removed. If the test is successful, the text "success" should be shown below.
<div id="container">
<div id="duplicate">This is the first duplicate div</div>
<div id="duplicate">This is the second duplicate div</div>
</div>
<ul id="console">
</li>
</body>
</html>
|