title: jQuery Add object to dynamic parent
body: <p>New to jQuery, having an issue with dynamically changing the selector.</p>
  
  <pre><code>&lt;html&gt;
    &lt;head&gt;
      &lt;script type="text/javascript" src="jquery.js"&gt;&lt;/script&gt;
      &lt;script&gt;
        function addFirst(){
          var fc = document.getElementById("fc").value;
          $("#parent").append("&lt;div id='firstChild" + fc + "'&gt;My boring text.&lt;/div&gt;&lt;a href='#' onClick='addSecond(\"firstChild" + fc +"\")'&gt;Add Second Child&lt;/a&gt;");
          fc = (fc - 1) + 2;
          document.getElementById("fc").value = fc;
      }
  
      function addSecond(){
        $(***THE PARENT SELECTOR***).append("&lt;div&gt;Some more boring text.&lt;/div&gt;");
      }
    &lt;/script&gt;
  
  
    &lt;body&gt;
      &lt;input type="hidden" id="fc" value="1"
      &lt;div id="parent"&gt;&lt;/div&gt;
      &lt;a href="#" onClick=" addFirst('#parent');"&gt;Add First Child&lt;/a&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I need a selector that gets me the direct parent of an object when that parent object has been created dynamically, as indicated by my text "<strong><em>THE PARENT SELECTOR</em></strong>".</p>
  
  <p><em><strong>EDIT</em></strong></p>
  
  <p>My solution to this, in case anyone else comes across this question, was to use .call inside the onClick event.</p>
  
  <p>Located in the string of the <strong>addFirst()</strong> function:</p>
  
  <pre><code>&lt;a href='#' onClick='addSecond.call(this,\"firstChild" + fc +"\"); return false;'&gt;
  </code></pre>
  
  <p>Then, changed the <strong>addSecond()</strong> function:</p>
  
  <pre><code>$(this.parentNode).prepend("&lt;div&gt;BlahBlah");
  </code></pre>