Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
10-05-2008, 09:54 PM #1
- Join Date
- Oct 2008
- Thanked 0 Times in 0 Posts
Making an Array of Total Nested Links
Okay, so here it goes:
Say I have a list of links inside a DIV with the ID "container":
And I want to make an array of all the links inside, but none outside, without using any preset variables (like making a variable called "links" holding the number "2" and then making an array called "totalLinks(links)" or something.*) I want it to be slightly more dynamic so that I don't have to go back in to the script every time I add or delete a link from that list inside that DIV.
I tried doing something equivalent to this:
myLinks = document.getElementById('container').links
I did the "links" part at the end because when used generally (like document.links) it should return an array of all of the links within the page. So, I figured when I use it in this context it would return an array of only the links within the specified element. It didn't quite work for some reason, though.
The code I'm using this in is a lot larger than this, and since I'm new it's kind of messy, so trouble shooting with alert boxes and such (which I try to do when I normally hit something stupid like this) wasn't the most helpful.
So, my question is, would anyone here mind enlightening me? As in, what's wrong here that I'm overlooking, or is there an alternative to do the same thing I'm attempting with a relatively small amount of code and as dynamic as possible (without much markup)?
10-06-2008, 01:12 AM #2
- Join Date
- May 2006
- Thanked 84 Times in 84 Posts