title: jquery load() strips script tags - workaround?
body: <p>Does anyone know of a work around for jquery .load() stripping out the script tags loaded from external content?</p>
  
  <p>There's a lot of documentation of the fact that this happens but after something like 4 hours searching the net I can't find a work around?</p>
  
  <p>I'm loading dynamically generated divs - similar to a page of search results - and need to bind a .click() to an element within each dynamically generated div. I've a php file that does the html generation work and returns all the html as a string however I can't bind the jquery .click() as the script tags containing the jquery function get stripped out.</p>
  
  <p>here's the code that loads the external content by calling the php file...</p>
  
  <pre><code>$("#titles_wrap").load("m_scripts/m_php/titles_loader.php", function(){
                                                                  $..some code
                                                                  });
  </code></pre>
  
  <p>and here's the loop from the php file that generates the divs (this works fine)...</p>
  
  <pre><code>$tag1='&lt;script type="text/javascript"&gt;';
  $tag2='&lt;/script&gt;';
  
  while($result_array = mysql_fetch_array($result)) {
  
              if($i2&lt;=($titles_total)){
  
                  $_SESSION['titles_string'] .= '&lt;li id="listItem_'.$i2.'"&gt;
  
                                                  &lt;div id="titles_list_item"&gt;
  
                                                      &lt;div id="titles_list_image_box" style="background-image: url(../../images/thumbs_test/'.$result_array[0].'); background-repeat: no-repeat; "&gt;'.($i2+1).'&lt;/div&gt;
                                                      &lt;div id="title_php_loader"&gt;&lt;/div&gt;
                                                          &lt;div id="title_info_wrap"&gt;
  
                                                          &lt;div id="title_current"&gt;&lt;span class="title_current_grey" &gt;current title: &lt;/span&gt;&lt;br&gt;'.$result_array[1].'
                                                              &lt;/div&gt;
  
                                                                  &lt;div id="title_form_wrap"&gt;
                                                                      &lt;span class="title_current_grey" &gt;new title: &lt;/span&gt;&lt;br&gt;&lt;input name="title_input_'.$i2.'" id="title_input_'.$i2.'" type="text" class="title_input"&gt;&lt;/input&gt;
                                                                      &lt;div id="title_send" class="title_send_'.$i2.'"&gt;GO&lt;/div&gt;
                                                                  &lt;/div&gt;
  
                                                              &lt;/div&gt;
  
  
                                                      '.$tag1.'
                                                      $(".title_send_'.$i2.'").click(function(){$("#title_php_loader").load("m_scripts/m_php/title_sender.php")})
                                                      '.$tag2.'
  
                                                  &lt;/div&gt;
                                              &lt;/li&gt;';
                  $i2++;
                                  }
              }
  </code></pre>
  
  <p>Sorry if this second code block is a bit on the 'overkill' side - let me know if a simplified excerpt would be more useful. That said, you can see on the 8th from last line of the php code the jquery function that should get written into each div with a dynamically assigned selector.</p>
  
  <p>Of course, it could be that there's other errors in the code however I'm not going to be able to test it until I can get .load() to stop trashing it!</p>
  
  <p>If anyone's found a solution to this - or even a workaround of limited grace - brilliant!</p>
  
  <p>Thanks in advance,</p>
  
  <p>Cheers,</p>
  
  <p>Scott</p>
  
  <p><strong>EDIT - EDIT - EDIT - EDIT - EDIT - EDIT - EDIT - EDIT</strong></p>
  
  <p>@T.J. Crowder 
  @Frug</p>
  
  <p>Thanks for your help! </p>
  
  <p>I've just had a good hard look at the pages involved in your demo and yes, I see you've got it working. Seems amazing cos there they are - those script tags and there are SO many people out there who can't get it to work - unfortunately I'm one of them! </p>
  
  <p>The only differences I see between your demo and my code situation was </p>
  
  <p>1) no type declaration in the opening script tag, </p>
  
  <p>2) you're loading a page with script tags as part of the DOM, whereas I was loading php string output (I really don't think this matters tho', eh? By the time it hits the client it all comes to the same thing, no?) </p>
  
  <p>3), your .load call was fetching a whole page whereas mine was returning only elements. I've since changed the output string to include all ,  and  tags but grrrrrr...I still can't get dem damn script tags to show up in the DOM. </p>
  
  <p>Any suggestions? There's loads I don't know about so could be anything! thanks S</p>