Reputation: 45
I googled my heart out on this one and looked at most of the AI suggestions after typing in the question, but did not find the answer. I have this:
<script>
<!-- JS return all element values of one tag type -->
var tagValues = document.getElementsByTagName('td');
var numTags = tagValues.length;
var retMessage = "The values of all elements with tag name 'td' are: \n\n";
var counter;
for (counter = 0; counter < numTags; counter++) {
retMessage = retMessage + document.getElementsByTagName("td")[counter].value + "\n";
}
alert(retMessage);
It returns undefined values for every element. the script is below all the HTML. I even tried an alternative (which is the way it should be written anyway) return line:
retMessage = retMessage + tagValues[counter].value + "\n";
the js fiddle also returns the same error. is this so simple I can't spot the error?
Upvotes: 0
Views: 22