Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
137
rated 0 times [  143] [ 6]  / answers: 1 / hits: 19172  / 12 Years ago, tue, march 5, 2013, 12:00:00
var all = document.getElementsByTagName(a);
for (var i=0, max=all.length; i < max; i++) {
alert(x.innerHTML);
}


The purpose of this script is obvious: it tries to loop through all the elements with the tag name a, and alert the contents of each one.



It doesn't run right.

It works fine, with one element, it alerts it's contents, but when there are more then one, it starts echoing undefined for each.


More From » javascript

 Answers
6

you should use alert(all[i].innerHTML). x is undefined


[#79806] Tuesday, March 5, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
faithemilys

Total Points: 418
Total Questions: 100
Total Answers: 114

Location: North Korea
Member since Fri, Nov 4, 2022
2 Years ago
;