Element-getElementsByClassName.html (1415B)
1 <!DOCTYPE html> 2 <title>Element.getElementsByClassName</title> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <div id="log"></div> 6 <script> 7 test(function() { 8 var a = document.createElement("a"), b = document.createElement("b") 9 b.className = "foo" 10 a.appendChild(b) 11 var list = a.getElementsByClassName("foo") 12 assert_array_equals(list, [b]) 13 var secondList = a.getElementsByClassName("foo") 14 assert_true(list === secondList || list !== secondList, "Caching is allowed.") 15 }, "getElementsByClassName should work on disconnected subtrees.") 16 17 test(function() { 18 var list = document.getElementsByClassName("foo") 19 assert_false(list instanceof NodeList, "NodeList") 20 assert_true(list instanceof HTMLCollection, "HTMLCollection") 21 }, "Interface should be correct.") 22 23 test(function() { 24 var a = document.createElement("a"); 25 var b = document.createElement("b"); 26 var c = document.createElement("c"); 27 b.className = "foo"; 28 document.body.appendChild(a); 29 this.add_cleanup(function() {document.body.removeChild(a)}); 30 a.appendChild(b); 31 32 var l = a.getElementsByClassName("foo"); 33 assert_true(l instanceof HTMLCollection); 34 assert_equals(l.length, 1); 35 36 c.className = "foo"; 37 a.appendChild(c); 38 assert_equals(l.length, 2); 39 40 a.removeChild(c); 41 assert_equals(l.length, 1); 42 }, "getElementsByClassName() should be a live collection"); 43 </script>