title: Difference between accessing a function and nested function in javascript
body: <p>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.</p>
  
  <p><strong>In other words, this works:</strong></p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Working with elements&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;script type="text/javascript"&gt;
  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);
  }
  
  &lt;/script&gt;
  
  &lt;body onload="addElement()"&gt;
  &lt;div id='org_div1'&gt; The text above has been created dynamically.&lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>This does not work:</strong></p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Working with elements&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;script type="text/javascript"&gt;
  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);
      }
  }
  
  &lt;/script&gt;
  
  &lt;body onload="addElement.getFieldSet()"&gt;
  &lt;div id='org_div1'&gt; The text above has been created dynamically.&lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>