summaryrefslogtreecommitdiffstats
path: root/dom/tests/js/docfrag.html
blob: f5520c94528f08b4dd6a5a2d92a51def8ba6352b (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
<HTML>
<HEAD>
<SCRIPT>
function docFragAppendTest() {
  var d = document.createDocumentFragment();
  d.appendChild(document.createTextNode(" Hello"));
  var b = document.createElement("B")
  b.appendChild(document.createTextNode(" there"));
  d.appendChild(b);
  p = document.getElementById("appendTest");
  p.appendChild(d);
  alert("This number should be 0: " + d.childNodes.length);
}
function docFragReplaceTest() {
  var d = document.createDocumentFragment();
  d.appendChild(document.createTextNode(" new"));
  var b = document.createElement("B")
  b.appendChild(document.createTextNode(" ones"));
  d.appendChild(b);
  p = document.getElementById("replaceTest");
  s = document.getElementById("replaceSpan");
  if (null != s) {
    p.replaceChild(d, s);
  }
  alert("This number should be 0: " + d.childNodes.length);
}
</SCRIPT>
</HEAD>
<BODY>
<H1>Document Fragment test</H1>

<P ID="appendTest">If this test works, clicking on this <A href="" onclick="docFragAppendTest(); return false;">link</A> will add two words to the end of this paragraph.</P>

<P ID="replaceTest">
Clicking on this <A href="" onclick="docFragReplaceTest(); return false;">link</A> will replace the following two words with new ones: <span id="replaceSpan">two words</span>.
</P>

</BODY>
</HTML>