chromedude
07-28-2010, 01:51 PM
Right now I am trying to grab all the links on a html page a store them in an array so that they can be accessed by a loop that makes sure that each one works. Right now I am not getting very far with it. If someone could help me I would be greatly appreciative.
gusblake
07-28-2010, 01:53 PM
What do you mean by not very far? Have you done this: var links=document.getElementsByTagName("a"); ?
chromedude
07-28-2010, 01:56 PM
no, does that store all the results in an array? because that is just a var
no, does that store all the results in an array? because that is just a var
var means variable. According to the nature of the right term, an assignment might give a variable two type of values: primitive and reference.
Now, getElementsByTagName() method returns always a collection of all the elements with a certain tagname (which is very much alike an array). So that variable in your example becomes the reference of that collection. A clone of the collection, we may say so.:)
chromedude
07-28-2010, 03:53 PM
Ok thanks. I am assuming you can access the values like an array? like link[0].
Ok thanks. I am assuming you can access the values like an array? like link[0].
Yes:
onload=function(){
var allA=document.getElementsByTagName('a');
for(var i=0;i<allA.length;i++){
alert(allA[i].href);
}
}