jQuery: Loading external HTML content; Access to elements inserted fails -


i load table element html (additional_content.html) current html via jquery. managed load content not able access elements inserted if not inserted. however, when inserting alert statement after load statement, able access elements of table inserted via load. appears me dom tree not updated immediately.

the code fragment within parent document looks this:

<div id="content"></div> <script>   $("#content").load("additonal_content.html #content table").hide();   $("#content").find("img").each(function() {     alert("test");   }); </script> 

and table within *additional_content.html" (excerpt):

<table>   <tr>     <td><img src="image1.gif"></td>     <td>some text...</td>   </tr>   <tr>     <td><img src="image2.gif"></td>     <td>some text...</td>   </tr> </table> 

it looks content hasn't loaded yet when hits 'find' statement.

try using callback, la:

<script> $("#content").load("additonal_content.html #content table",function(){  $("#content").find("img").each(function() {     alert("test");  }); });  </script> 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -