|
1 <HTML> |
|
2 <HEAD> |
|
3 <SCRIPT> |
|
4 function docFragAppendTest() { |
|
5 var d = document.createDocumentFragment(); |
|
6 d.appendChild(document.createTextNode(" Hello")); |
|
7 var b = document.createElement("B") |
|
8 b.appendChild(document.createTextNode(" there")); |
|
9 d.appendChild(b); |
|
10 p = document.getElementById("appendTest"); |
|
11 p.appendChild(d); |
|
12 alert("This number should be 0: " + d.childNodes.length); |
|
13 } |
|
14 function docFragReplaceTest() { |
|
15 var d = document.createDocumentFragment(); |
|
16 d.appendChild(document.createTextNode(" new")); |
|
17 var b = document.createElement("B") |
|
18 b.appendChild(document.createTextNode(" ones")); |
|
19 d.appendChild(b); |
|
20 p = document.getElementById("replaceTest"); |
|
21 s = document.getElementById("replaceSpan"); |
|
22 if (null != s) { |
|
23 p.replaceChild(d, s); |
|
24 } |
|
25 alert("This number should be 0: " + d.childNodes.length); |
|
26 } |
|
27 </SCRIPT> |
|
28 </HEAD> |
|
29 <BODY> |
|
30 <H1>Document Fragment test</H1> |
|
31 |
|
32 <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> |
|
33 |
|
34 <P ID="replaceTest"> |
|
35 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>. |
|
36 </P> |
|
37 |
|
38 </BODY> |
|
39 </HTML> |