Jquery - Loading a page with .load and selector doesn't execute script?
<p>I'm trying to load one page into another using the .load() method. This loaded page contains a script that I want to execute when it has finished loading. I've put together a barebones example to demonstrate:</p>

<p><strong>Index.html:</strong></p>

<pre><code>&lt;html&gt;
&lt;head&gt;
 &lt;title&gt;Jquery Test&lt;/title&gt;
 &lt;script type="text/javascript" src="script/jquery-1.3.2.min.js"&gt;&lt;/script&gt;
 &lt;script type="text/javascript"&gt;
  $(document).ready(function()
  {
    $('#nav a').click(function()
    {
      $('#contentHolder').load('content.html #toLoad', '', function() {});        
      return false;
    });
  });
 &lt;/script&gt;    
&lt;/head&gt;
&lt;body&gt;
 &lt;div id="nav"&gt;
  &lt;a href="content.html"&gt;Click me!&lt;/a&gt;
 &lt;/div&gt;
 &lt;hr /&gt;
 &lt;div id="contentHolder"&gt;
  Content loaded will go here
 &lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p><strong>Content.html:</strong></p>

<pre><code>&lt;div id="toLoad"&gt;
 This content is from content.html

 &lt;div id="contentDiv"&gt;
    This should fade away.
 &lt;/div&gt;

 &lt;script type="text/javascript"&gt;
  $('#contentDiv').fadeOut('slow', function() {} );
 &lt;/script&gt;
&lt;/div&gt;
</code></pre>

<p>When the link is clicked, the content should load and the second paragraph should fade away. However it doesn't execute. If I stick a simple alert("") in the script of content.html it doesn't execute either.</p>

<p>However, if I do away with the #toLoad selector in the .load() call, it works fine. I am not sure why this is, as the  block is clearly in the scope of the #toLoad div. I don't want to avoid using the selector, as in reality the content.html will be a full HTML page, and I'll only want a select part out of it.</p>

<p>Any ideas? If the script from content.html was in the .load() callback, it works fine, however I obviously don't want that logic contained within index.html.</p>

<p>I could possibly have the callback use .getScript() to load "content.html.js" afterwards and have the logic in there, that seems to work? I'd prefer to keep the script in content.html, if possible, so that it executes fine when loaded normally too. In fact, I might do this anyway, but I would like to know <em>why</em> the above doesn't work.</p>
