test_getElementById.xhtml (2036B)
1 <html xmlns="http://www.w3.org/1999/xhtml"> 2 <head> 3 <title>Test getElementById behaviour</title> 4 <script src="/tests/SimpleTest/SimpleTest.js"></script> 5 <script type="text/javascript" src="matrixUtils.js"></script> 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 7 </head> 8 <body> 9 <p id="display"></p> 10 <div id="content"> 11 <svg xmlns="http://www.w3.org/2000/svg" width="100%" height="1" id="svg"> 12 <!-- decoy element, same Id but not a <g> --> 13 <rect id="g"/> 14 <svg id="inner"> 15 <!-- the one we want to find --> 16 <g id="g"/> 17 <!-- check we don't get confused by CSS selectors --> 18 <g id="foo bar"/> 19 <g id="goo > car"/> 20 <g id="hoo~dar"/> 21 <g id="ioo+ear"/> 22 </svg> 23 <g id="g2"/> 24 </svg> 25 </div> 26 <pre id="test"> 27 <script class="testbody" type="text/javascript"> 28 <![CDATA[ 29 30 SimpleTest.waitForExplicitFinish(); 31 32 function main() { 33 var svgns = "http://www.w3.org/2000/svg"; 34 35 var svg = document.getElementById("inner"); 36 37 is(svg.getElementById("g").nodeName, "g", "expected to find g element child"); 38 is(svg.getElementById("foo bar").nodeName, "g", "expected to find foo bar element child"); 39 is(svg.getElementById("goo > car").nodeName, "g", "expected to find goo > car element child"); 40 is(svg.getElementById("hoo~dar").nodeName, "g", "expected to find hoo~dar element child"); 41 is(svg.getElementById("ioo+ear").nodeName, "g", "expected to find ioo+ear element child"); 42 43 is(svg.getElementById("g2"), null, "did not expect to find an element with id g2"); 44 45 // no element with Id = "g3" in the document at all 46 is(svg.getElementById("g3"), null, "did not expect to find an element with id g3"); 47 48 svg = document.createElementNS(svgns, "svg"); 49 50 var c = document.createElementNS(svgns, "circle"); 51 c.setAttribute("id", "c"); 52 svg.appendChild(c); 53 54 is(svg.getElementById("c").nodeName, "circle", "expected to find circle element child"); 55 56 SimpleTest.finish(); 57 } 58 59 window.addEventListener("load", main); 60 61 ]]> 62 </script> 63 </pre> 64 </body> 65 </html>