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

    Help: return window.open array

    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


  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Between DC and Baltimore In a Cave
    Thanked 94 Times in 88 Posts
    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');

    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]


    Posting Permissions

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