Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Unhappy how to store event results in array

    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.

  • #2
    Regular Coder
    Join Date
    Jan 2006
    Posts
    568
    Thanks
    6
    Thanked 84 Times in 84 Posts
    What do you mean by not very far? Have you done this: var links=document.getElementsByTagName("a"); ?

  • #3
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    no, does that store all the results in an array? because that is just a var

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Quote Originally Posted by chromedude View Post
    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.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Ok thanks. I am assuming you can access the values like an array? like link[0].

  • #6
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Quote Originally Posted by chromedude View Post
    Ok thanks. I am assuming you can access the values like an array? like link[0].
    Yes:
    Code:
    onload=function(){
    var allA=document.getElementsByTagName('a');
    for(var i=0;i<allA.length;i++){
    alert(allA[i].href);
    }
    }
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •