test_getElementById.html (1957B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=933193 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test for Bug 933193</title> 9 <script src="/tests/SimpleTest/SimpleTest.js"></script> 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 11 </head> 12 <body> 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=933193">Mozilla Bug 933193</a> 14 <p id="display"></p> 15 <div id="content" style="display: none"> 16 17 </div> 18 <pre id="test"> 19 </pre> 20 <script type="application/javascript"> 21 22 /** Test for Bug 933193 */ 23 var kid = document.createElement("span"); 24 kid.id = "test"; 25 var svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"); 26 svg.appendChild(kid); 27 is(svg.getElementById("test"), kid, 28 "Should find the right node when not in the DOM"); 29 30 var newKid = document.createElement("span"); 31 newKid.id = "test"; 32 var newKidParent = document.createElement("span"); 33 newKidParent.appendChild(newKid); 34 svg.insertBefore(newKidParent, kid); 35 is(svg.getElementById("test"), newKid, 36 "Should find the first right node when not in the DOM"); 37 newKid.remove(); 38 is(svg.getElementById("test"), kid, 39 "Should find the right node again when not in the DOM"); 40 41 document.body.appendChild(svg); 42 is(svg.getElementById("test"), kid, 43 "Should find the right node when in the DOM"); 44 45 is(document.getElementById("test").localName, "pre", 46 "document.getElementById should find the first element in the " + 47 "document with that id"); 48 49 var frag = document.createDocumentFragment(); 50 is(frag.getElementById("test"), null, "Shouldn't find what does not exist"); 51 frag.appendChild(kid); 52 is(frag.getElementById("test"), kid, 53 "Should find the right node in the document fragment"); 54 is(svg.getElementById("test"), null, 55 "Shouldn't find the kid since it's gone now"); 56 </script> 57 </body> 58 </html>