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 8079351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:04:27+00:00 2026-06-05T16:04:27+00:00

I am trying to work out why I can not access the nested function

  • 0

I am trying to work out why I can not access the nested function in a similar way as I can when I am just accessing an un-nested function (maybe there is a better way to explain this.

In other words, this works:

<html>
<head>
<title>Working with elements</title>
</head>

<script type="text/javascript">
var my_div = null;
var newDiv = null;

function addElement()
{
  // create a new div element
  // and give it some content
  newDiv = document.createElement("div");
  newContent = document.createTextNode("Hi there and greetings!");
  newDiv.appendChild(newContent); //add the text node to the newly created div.

  // add the newly created element and it's content into the DOM
  my_div = document.getElementById("org_div1");
  document.body.insertBefore(newDiv, my_div);
}

</script>

<body onload="addElement()">
<div id='org_div1'> The text above has been created dynamically.</div>
</body>
</html>

This does not work:

<html>
<head>
<title>Working with elements</title>
</head>

<script type="text/javascript">
var my_div = null;
var newDiv = null;

function addElement()
{
    this.getFieldset = function() {
        // create a new div element
        // and give it some content
        newDiv = document.createElement("div");
        newContent = document.createTextNode("Hi there and greetings!");
        newDiv.appendChild(newContent); //add the text node to the newly created div.

        // add the newly created element and it's content into the DOM
        my_div = document.getElementById("org_div1");
        document.body.insertBefore(newDiv, my_div);
    }
}

</script>

<body onload="addElement.getFieldSet()">
<div id='org_div1'> The text above has been created dynamically.</div>
</body>
</html>
  • 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-06-05T16:04:28+00:00Added an answer on June 5, 2026 at 4:04 pm

    It’s because you never executed addElement() in the second case in order to execute the this.getFieldset = ... assignment.

    You could change your code to

    function addElement() {}
    
    addElement.getFieldSet = function() {
            // create a new div element
            // and give it some content
            newDiv = document.createElement("div");
            newContent = document.createTextNode("Hi there and greetings!");
            newDiv.appendChild(newContent); //add the text node to the newly created div.
    
            // add the newly created element and it's content into the DOM
            my_div = document.getElementById("org_div1");
            document.body.insertBefore(newDiv, my_div);
        };
    

    EDIT

    See example at this fiddle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just trying to work out if something is possible or not with SCSS.
I can not work out the javascript syntax to access elements of the following,
I have a generic Collection and am trying to work out how I can
I'm trying to work out how, after changing style properties with javascript, I can
Im trying to work out the best way to approach the following problem with
I'm trying to work out the best way to assemble the navigation menu of
I am trying to work out the best way of using a viewmodel in
I am trying to work out how to access data in an essentially multidimensional
I am trying to work out a way to use dependency injection with ASP.NET
I'm trying to make simpleModal jquery script to work, but cannot figure out what

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.