nodelist-item-with-index.html revision eff69b907ef2cd3a9af0351287a929c66f58e3f6
1<html>
2<head>
3<link rel="stylesheet" href="/js/resources/js-test-style.css">
4<script src="/js/resources/js-test-pre.js"></script>
5</head>
6<body>
7<p id="description"></p>
8<div id='div1'>text1</div>
9<div id='div2'>text2</div><br>
10
11<div id="console"></div>
12
13<script>
14description('This tests that items in a NodeList can be retrieved by index.');
15
16var nodeList = document.getElementsByTagName('div');
17var div0 = nodeList[0];
18var div0s = nodeList["0"];
19var div0s_ = nodeList["0 "];
20var div1 = nodeList["1"];
21
22// Getting properties 0 and "0" should get the same thing, but getting
23// properties "0 " and 1 should get different items.  "0 " should not
24// be converted to 0, so should be undefined, and the item at index
25// 1 should be defined (since there are at least two divs on the page),
26// but should be a different div to the one at index 0.
27shouldBeTrue("div0 == div0s");
28shouldBeFalse("div0 == div0s_");
29shouldBeFalse("div0 == div1");
30shouldBeFalse("div0s == div0s_");
31shouldBeFalse("div0s == div1");
32shouldBeFalse("div0s_ == div1");
33
34var successfullyParsed = true;
35</script>
36<script src="/js/resources/js-test-post.js"></script>
37</body>
38</html>
39