[jQuery] how to load and change the external HTML fragment with AJAX

[jQuery] how to load and change the external HTML fragment with AJAX


Hi, I want to load a fragment of external html document
(external.html#embeddedContent) with the help of AJAX call, embed
(inject) this into my HTML document (main.html#placeToInject), and
change this embedded fragment a little.
I think that I need load this external fragment and either 1) change
this before injection, or 2) inject and change at once before user
will notice anything. The both possibilities are ok for me now, but I
have a problem with manipulating and filtering the embedded fragment
while working with jquery 1.2.1.
If I follow the second (2) way, I need to do any manipulation only
when content has been already injected into the code.
But the following code doesn’t work. Means $(“..”) below relates to
original fragment in main.html that has been presented there before
injection. See comments in the code.
$(document).ready(function(){
// load and inject content
var content = "main.html";
$("#placeToInject").load(content + " #embeddedContent