.load is asynchronous, which means that it returns (and the next statement is
executed) before it finishes loading.
So 
   $("#left").load("test.html");
starts loading #left with test.html
but
   $("#left").css("border","1px solid red");
executes within milliseconds, and test.html probably hasn't come back from
the server yet. You need to use a callback (
http://docs.jquery.com/Ajax/load#urldatacallback ):
  $("#left").load("test.html", function(){
     $("#left").css("border","1px solid red");
     etc.
  });

That ought to work!

Danny

Sagari-2 wrote:
> 
> 
> Greetings,
> 
> I have a nasty surprise: jQuery (1.2.1) won't access DOM elements that
> have been inserted via .load() function.
> 
> Example:
> 
> index.html:
> ---------------
> 
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/
> xhtml1-transitional.dtd">
> <html><head><title>Test</title>
> <script type="text/javascript" src="jquery.js"></script>
> <script type="text/javascript" src="test.js"></script>
> </head><body>
> <div id="left" style="float: left; width: 30%">
> Left
> </div>
> <div id="left" style="float: right; width: 69%">
> Right
> </div>
> </body>
> </html>
> 
> test.js:
> ---------
> 
> $(document).ready(prolog);
> 
> function prolog() {
>   $("#left").load("test.html");
>   $("#left").css("border","1px solid red");
>   $("#test").css("border","1px solid green");
>   $("#left #test").css("border","1px solid green");
> }
> 
> test.html:
> -------------
> 
> <div id="test">
> Test
> </div>
> 
> After I load the index.html, I expect to see the "#left" div
> containing the test.html content; with #left with red border and #test
> with green.
> 
> However, #test has no green border; in fact, I can't at all address
> the newly loaded HTML part, as it were not exist at all. I tried two
> kidns of addressing (in the test.js above) with no effect.
> 
> How can I address the HTMl loaded via .load() function?
> 
> Thanks.
> 
> All the best,
> 
> Konstantin
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Lookup-doesn%27t-work-within-HTML-loaded-with-.load%28%29-tf4692256s27240.html#a13417814
Sent from the jQuery General Discussion mailing list archive at Nabble.com.

Reply via email to