Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-28-2010, 01:51 PM   PM User | #1
chromedude
New to the CF scene

 
Join Date: Jul 2010
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
chromedude is an unknown quantity at this point
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.
chromedude is offline   Reply With Quote
Old 07-28-2010, 01:53 PM   PM User | #2
gusblake
Regular Coder

 
Join Date: Jan 2006
Posts: 568
Thanks: 6
Thanked 84 Times in 84 Posts
gusblake is on a distinguished road
What do you mean by not very far? Have you done this: var links=document.getElementsByTagName("a"); ?
gusblake is offline   Reply With Quote
Old 07-28-2010, 01:56 PM   PM User | #3
chromedude
New to the CF scene

 
Join Date: Jul 2010
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
chromedude is an unknown quantity at this point
no, does that store all the results in an array? because that is just a var
chromedude is offline   Reply With Quote
Old 07-28-2010, 03:40 PM   PM User | #4
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
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
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Old 07-28-2010, 03:53 PM   PM User | #5
chromedude
New to the CF scene

 
Join Date: Jul 2010
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
chromedude is an unknown quantity at this point
Ok thanks. I am assuming you can access the values like an array? like link[0].
chromedude is offline   Reply With Quote
Old 07-28-2010, 04:18 PM   PM User | #6
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
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
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Reply

Bookmarks

Tags
arrays, events, javascript

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:59 AM.


Advertisement
Log in to turn off these ads.