Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6190673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:37:48+00:00 2026-05-24T02:37:48+00:00

This question follows my previous question here in case anyone is interested. I am

  • 0

This question follows my previous question here in case anyone is interested.

I am creating a window via window.open() then calling this function (from within the child window) when the window has loaded (via onload). This function, which I borrowed from a tutorial, basically creates tabbed text areas.

function appendToBody(){
    for (moduleName in codes){
        //create text area
        console.log(moduleName+' creating text area');
        var textArea = document.createElement('textarea');
        textArea.setAttribute('rows', '30');
        textArea.setAttribute('cols', '105');
        textArea.value = codes[moduleName];
        console.log(textArea);

        //create div
        console.log(moduleName+' creating div');
        var div = document.createElement('div');
        div.setAttribute('class', 'tabContent');
        div.setAttribute('id', moduleName);
        div.appendChild(textArea);
        console.log(div);

        //create link
        console.log(moduleName+' creating link');
        var link = document.createElement('a');
        link.setAttribute('href', '#' + moduleName);
        console.log(link);

        //add link to li
        console.log(moduleName+' adding link to li');
        var li = document.createElement('li');
        li.appendChild(link);
        console.log(li);

        //add li to ul
        console.log(moduleName+' Adding li to ul');
        var ul = document.getElementById('tabs');
        ul.appendChild(li);
        console.log(ul);
    }
  foo();
}

The function foo then does some preprocessing and looks like so (I mostly copy pasted this code)

var tabLinks = new Array();
var contentDivs = new Array();

function init() {

    // Grab the tab links and content divs from the page
    var tabListItems = document.getElementById('tabs').childNodes;
    for ( var i = 0; i < tabListItems.length; i++ ) {
        if ( tabListItems[i].nodeName == "LI" ) {
            var tabLink = getFirstChildWithTagName( tabListItems[i], 'A' );
            var id = getHash( tabLink.getAttribute('href') );
            tabLinks[id] = tabLink;
            contentDivs[id] = document.getElementById( id );
        }
    }
}

document.getElementById('tabs') works as tabs is hard coded in the document body, but document.getElementById( id ), which was dynamically created, returns null. I checked the names and they are identical. Is there anything extra I need to consider when dynamically creating elements.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T02:37:49+00:00Added an answer on May 24, 2026 at 2:37 am

    You have mistaken “nodeName” for “tagName” in your init function’s if. Beware that childNodes will return all nodes (other DOM elements AND text nodes) and I’m pretty sure that text nodes do not have a tagName property, so you’d likely get a javascript error there. I suggest 2 changes. Instead of childNodes, use children (just the DOM elements). And instead of nodeName use tagName:

    var tabListItems = document.getElementById('tabs').children;
    for ( var i = 0; i < tabListItems.length; i++ ) {
        if ( tabListItems[i].tagName == "LI" ) {
            var tabLink = getFirstChildWithTagName( tabListItems[i], 'A' );
            var id = getHash( tabLink.getAttribute('href') );
            tabLinks[id] = tabLink;
            contentDivs[id] = document.getElementById( id );
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question follows on from a previous question which can be found here: Need
This follows on from a previous question here where I asked how to develop
This question follows on from a previous question, that has raised a further issue.
This problem follows on from a previous question . When I run the following
OK, this kind of follows on from my previous question . What I would
This is a follow up to my previous question: Problem passing parameters via Iframe
All, this is a follow up from a previous question here: C# formatting external
This is a follow-up to my previous question (found here ). My properties files
This is a follow up question from my previous one found here I need
This follows my previous question about TFS 2010 and the possibility to create a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.