title: jQuery: How to modify loaded content from inside load callback
body: <p>I'm dynamically creating a number of div elements (rows). Every row will have the same basic format, only text changes. As the row structure is complex, I'm trying to load a "basic" div from a static html file, and then once loaded, tweak some of the attributes with each row's params. (Something like Android's xml-defined adapters). I'm using jQuery and jQuery Mobile.</p>
  
  <p>I call this function several times (once per row). On each call I pass as parameters a <code>params</code> object, containing the data for that row, and a newly created div element (created with <code>document.createElement("div")</code>):</p>
  
  <pre><code>    function loadRow(params, div){  
          var $div = $(div);        
  
          $div.load("some_page.html [data-custom-role=row]", function(){
              //FIXME Throws error: object is not a function!!
              var nameElement = $div("[data-custom-role=name]");
              nameElement.text(params.name);
          });
      }
  </code></pre>
  
  <p><br>This code throws this error in the first line below the FIXME comment:<br></p>
  
  <pre><code>Uncaught type Error: object is not a function
  </code></pre>
  
  <p><br>The (simplified) content of the source html file (some_page.html):</p>
  
  <pre><code>    &lt;!DOCTYPE html&gt;
      &lt;html&gt;
          &lt;head&gt;
              &lt;meta charset="ISO-8859-1"&gt; 
          &lt;/head&gt;
          &lt;body&gt;
              &lt;div data-custom-role="row"&gt;
                  &lt;p data-custom-role="name"&gt;&lt;/p&gt;
              &lt;/div&gt;
          &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p><p>What I'm trying to do is to select the "p" element inside that newly loaded div, and set the text content. I can't use the id to identify the "p" element because I'll later inject all the rows to the page, and there can't exist 2 elements with the same id. That's why I need to use an attribute as selector, but as many rows would be loading at the same time, I need to make sure I'm only tweaking the "p" element inside the div I'm loading, and not other row divs. I thought the variable <code>$div</code> would be available inside the callback because a closure is created.</p>
  
  <p>What am I doing wrong? How could I query and modify the loaded content inside the callback?</p>
  
  <p>Thanks in advance.</p>