I have just recently begun to put getElementsByTagName() to good use! Testing different things! I wrote the following script and came upon a question! I have used this method with tag names getElementsByTagName('div/a/span'), and I guess getElementsByTagName('*') is all the tags on the page! I wondered if you could reference them in there order on the page like this getElementsByTagName(1) this being the second tag on the page the <head>? Can this be done thanx?
Code:<html> <head> <script language="Javascript"> function reference(unique,id,clsName){ this.unique=unique; this.id=id; this.clsName=clsName; } data=new Array(); window.onload=function alt(){ for(var i=0;i<document.getElementsByTagName('div').length;i++){ data[i]=new reference(document.getElementsByTagName('div')[i].tagName+i, document.getElementsByTagName('div')[i].id, document.getElementsByTagName('div')[i].className); } } </script> </head> <body> <div id="div_0" class="box_0" onclick="alert(data[0].unique)">text</div> <div id="div_1" class="box_1">text</div> <div id="div_2" class="box_2">text</div> </body> </html>




For example, getElementsByTagName(0) should return the <html> element.


Bookmarks