Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting length from getElementsFromTagName Array 1

Status
Not open for further replies.

cellpeter

Programmer
Dec 30, 2004
34
US
Ok What I wanted to do is to get the string length of a hyperlink from the getElementsByTagName array...

But for some reason the alert keeps saying undefined.. I have no idea what the problem is..

I tried to create an array in the code itself and I was able to get the length of the element...

-------

Here is the code if it helps..

---

<html>
<head>
<style type="text/css">
a{color:red;background:eek:range}
.goo:first-letter{font-size:16pt;color:darkblue}
</style>
<script language=javascript>
function tt(){
AA = document.getElementsByTagName('a');
CC = AA.length;
teen = new Array();
for(TT = 0;TT < AA.length;TT++)
{
teen[TT] = AA[TT]

}

alert(teen[0].length)



}




</script>



</head>
<body onLoad=tt()>
<div align=center>
<a href="<a href="<a href="</div>
<div class=goo>
this is just a test to see if something will change or not </div>
</body>
</html>
 
>[tt]alert(teen[0].length)[/tt]
Should be this.
[tt]alert(teen.length)[/tt]
teen[0] is the reference to the first anchor element itself.
 
>the string length of a hyperlink ...

Maybe this is what you're looking for.
[tt] alert(teen[0].innerHTML.length);[/tt]
and also maybe this as well.
[tt] alert(teen[0].href.length);[/tt]
 
Thank you so much!

Your solution worked perfectly
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top