jQuery.ready is executed when the main document is loaded completely. Loading markup from a separate AJAX call from the main document is not included. As ken mentioned, option #2 is probably the best way to go. #1 will not always work (might not even work at all) because you're racing against the AJAX response time.
On Apr 23, 5:51 am, ken <jqu...@kenman.net> wrote: > #2 will probably be your best bet. I am pretty sure that if the page > you're retrieving has <script> blocks, they'll be parsed out and > inserted into the <head> of the document -- before the actual HTML is > injected into the <body>. > > On Apr 23, 9:30 am, Brandon <brandon.goo...@gmail.com> wrote: > > > Greetings All, > > > I am loading content into a page using the following: > > > $("#someDiv).load("/Some.action",{id: someId}); > > > The document that results from Some.action contains javascript at the > > top. I want the javascript to be executed when the resulting content > > is fully ready/loaded. > > > I attempted to use the document ready: > > > <script type="text/javascript"> > > $(function() { > > console.log("READY"); > > }); > > </script> > > > However the document is already ready since I am loading it into an > > existing page. I see READY in the console before the content is > > finished rendering. > > > The only solutions I could come up with were: > > 1) Place the javascript at the bottom of the loaded page so that the > > prior DOM will have been loaded. > > 2) Place javascript into the callback function of the $ > > ("#someDiv).load(...) call. > > > Number 1 is fine. I'm just wondering if this is an acceptable way or > > if there is a better way. > > Number 2 is not acceptable because the fragment may be called from > > several other locations and I don't want repetitious code. > > > Am I being thick headed here? Is there another better way? > > > Brandon