008.xml (1742B)
1 <html xmlns="http://www.w3.org/1999/xhtml"> 2 <head> 3 <title>DOM Traversal: NodeIterator: Removal of an ancestor of the Reference Node (backwards)</title> 4 <script type="text/javascript"> <![CDATA[ 5 var errors = 0; 6 var log = ''; 7 function doTest() { 8 var iterator = document.createNodeIterator(document.getElementById('root'), NodeFilter.SHOW_ALL, null, false); 9 var root = document.getElementById('root'); 10 var A = document.getElementById('A'); 11 var B = document.getElementById('B'); 12 var BB = document.getElementById('BB'); 13 var C = document.getElementById('C'); 14 check(iterator.nextNode(), root); 15 check(iterator.nextNode(), A); 16 check(iterator.nextNode(), B); 17 check(iterator.nextNode(), BB); 18 check(iterator.previousNode(), BB); 19 remove(B); 20 check(iterator.nextNode(), C); 21 if (errors) 22 document.getElementById('result').firstChild.data = 'FAIL: ' + errors + ' errors:\n' + log; 23 else 24 document.getElementById('result').firstChild.data = 'PASS'; 25 } 26 function check(a, b) { 27 if (!a) { 28 errors += 1; 29 log += 'Found null but expected ' + b + ' (' + b.id + ').\n'; 30 } else if (a != b) { 31 errors += 1; 32 log += 'Found ' + a + ' (' + a.id + ') but expected ' + b + ' (' + b.id + ').\n'; 33 } 34 } 35 function remove(a) { 36 if (!a) { 37 errors += 1; 38 log += 'Tried removing null node.\n'; 39 } else 40 a.parentNode.removeChild(a); 41 } 42 ]]></script> 43 </head> 44 <body onload="doTest()"> 45 <pre id="result">FAIL: Script did not complete.</pre> 46 <p><span id="root"><span id="A"></span><span id="B"><span id="BB"></span></span><span id="C"></span></span></p> 47 </body> 48 </html>