summaryrefslogtreecommitdiffstats
path: root/dom/tests/js/lists.html
blob: eecb345f954d6a96938e9f97b7f70878f191cda3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<html>
<body>
<p>This test does a few things:
<ul>
  <li>It has a couple of:
  <ul>
      <li>Images: <IMG SRC="http://zabadubop/layers/tests/mzcolor.gif" ID="foo"> and
          <IMG SRC="http://peoplestage.netscape.com/kipp/nerdly_int.gif" NAME="kipp">.
      <li>Links to <a href="http://home.netscape.com">Netscape</a> and
          <A HREF="http://peoplestage.netscape.com/kipp">Kippy's Home Page</A>.
      <li>and Anchors to <a NAME="anchor1">here</A> and 
          <A name="anchor2">here</a>.
  </ul>
  <li>It dumps (check the JS console) the images, links and anchors using
      the document.images, document.links and document.anchors arrays.
  <li>Then it removes one of the images.
  <li>Dumps the images array again. This is to prove that the images array
      is live.
  <li>Adds back the image.
  <li>And the dumps the images array again. The image arrays order should
      now be different.
  <li>It gets a list of LIs (using getElementsByTagName()) and prints
      out all their tagNames. There should be 10.
</ul>
<script>
var x;
dump("Images:\n");
for (x=0; x < document.images.length; x++) {
  dump("Image#" + x + ": " + document.images[x].getDOMAttribute("SRC") + "\n");
}
dump("\nLinks:\n");
for (x=0; x < document.links.length; x++) {
  dump("Link#" + x + ": " + document.links[x].getDOMAttribute("HREF") + "\n");
}
dump("\nAnchors:\n");
for (x=0; x < document.anchors.length; x++) {
  dump("Anchors#" + x + ": " + document.anchors[x].getDOMAttribute("NAME") + "\n");
}

dump("\nRemoving image\n");
var img=document.images[1];
var parent=img.parentNode;
parent.removeChild(img);
dump("Images:\n");
for (x=0; x < document.images.length; x++) {
  dump("Image#" + x + ": " + document.images[x].getDOMAttribute("SRC") + "\n");
}

dump("\nInserting image back into list\n");
var sib=parent.childNodes[0];
parent.insertBefore(img, sib);
dump("Images:\n");
for (x=0; x < document.images.length; x++) {
  dump("Image#" + x + ": " + document.images[x].getDOMAttribute("SRC") + "\n");
}

var lis = document.getElementsByTagName("LI");
dump("Lists:\n");
for (x=0; x < lis.length; x++) {
  dump(lis[x].tagName + "\n");
}

dump("Named elements:\n");
dump(document.kipp.tagName + " with NAME=" + document.kipp.getDOMAttribute("NAME") + "\n");

</script>
</body>
</html>