View Full Version : Help: return window.open array

08-20-2005, 07:47 AM
Hi there,

It has been a few years since i have had to really think about JS and i am having problems.

I want to build an array of all the div id's on the page and then return that var to be used by other functions.

Can someone help me out here...

what i have working is this.

window.onload = function() {
var ids = document.getElementById('content').getElementsByTagName('div');
for (var i=0;i<ids.length;i++){
alert(ids[i].id); }

but the end result is that i remove the red lines and return the var ids to be used by other functions.

Any and all help very appreciated.
but the end result is that i remove the


08-21-2005, 06:12 AM
Welcome to the forum, but it looks like you posted a question and not a complete script which this forum is meant for. (Guess you forgot to read the big the rules.)

To answer your question. You are using a local variable and not a global variable. Hence only the variable will be able to be used in that function and not in the rest of the script. That is why you are running into that problem.

The solution is make it global:
var ids;
window.onload = function() {
ids = document.getElementById('content').getElementsByTagName('div');