Source code

Revision control

Other Tools

Test Info:

<!DOCTYPE html>
<meta charset=utf-8>
<title>Named items: imgs</title>
<link rel="author" title="Ms2ger" href="mailto:ms2ger@gmail.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<div id="test">
<img name=test1>
<img name=test2>
<img name=test2>
<img id=test3>
<img id=test4>
<img id=test4 name="">
<img name=test5>
<img id=test5>
<img id=test6>
<img name=test6>
<img id=test7 name=fail>
<img name=test8 id=fail>
</div>
<script>
test(function() {
var img = document.getElementsByTagName("img")[0];
assert_equals(img.name, "test1");
assert_true("test1" in document, '"test1" in document should be true');
assert_equals(document.test1, img);
}, "If there is one img, it should be returned (name)");
test(function() {
var img1 = document.getElementsByTagName("img")[1];
assert_equals(img1.name, "test2");
var img2 = document.getElementsByTagName("img")[2];
assert_equals(img2.name, "test2");
assert_true("test2" in document, '"test2" in document should be true');
var collection = document.test2;
assert_class_string(collection, "HTMLCollection", "collection should be an HTMLCollection");
assert_array_equals(collection, [img1, img2]);
}, "If there are two imgs, a collection should be returned. (name)");
test(function() {
var img = document.getElementsByTagName("img")[3];
assert_equals(img.id, "test3");
assert_false("test3" in document, '"test3" in document should be false');
assert_equals(document.test3, undefined);
}, "If there is one img, it should not be returned (id)");
test(function() {
var img1 = document.getElementsByTagName("img")[4];
assert_equals(img1.id, "test4");
var img2 = document.getElementsByTagName("img")[5];
assert_equals(img2.id, "test4");
assert_false("test4" in document, '"test4" in document should be false');
assert_equals(document.test4, undefined);
}, "If there are two imgs, nothing should be returned. (id)");
test(function() {
var img1 = document.getElementsByTagName("img")[6];
assert_equals(img1.name, "test5");
var img2 = document.getElementsByTagName("img")[7];
assert_equals(img2.id, "test5");
assert_true("test5" in document, '"test5" in document should be true');
assert_equals(document.test5, img1);
}, "If there are two imgs, the one with a name should be returned. (name and id)");
test(function() {
var img1 = document.getElementsByTagName("img")[8];
assert_equals(img1.id, "test6");
var img2 = document.getElementsByTagName("img")[9];
assert_equals(img2.name, "test6");
assert_true("test6" in document, '"test6" in document should be true');
assert_equals(document.test6, img2);
}, "If there are two imgs, the one with a name should be returned. (id and name)");
test(function() {
var img = document.getElementsByTagName("img")[10];
assert_equals(img.id, "test7");
assert_true("test7" in document, '"test7" in document should be true');
assert_equals(document.test7, img);
}, "A name should affect getting an img by id");
test(function() {
var img = document.getElementsByTagName("img")[11];
assert_equals(img.name, "test8");
assert_true("test8" in document, '"test8" in document should be true');
assert_equals(document.test8, img);
}, "An id shouldn't affect getting an img by name");
</script>