I made some tests with the load() command of jQuery, something like: $('').load('my.html div#content', function(){ etc. I was surprised to see that I was able to retrieve the div#content but not its child elements. When I substituted div#content by any of the child descriptors, e.g. a.opts I got the expected result - in this case, all the .opts links. However I have many different kind of elements inside my div#content; shoud I call them one by one, with a new load() statement, or am I doing something wrong?
A:
load() will get the element you specify and all its child elements. It could be there's something wrong with the selector you're using. Could you post some code?
EDIT: I'm guessing the selectors you're using are to blame. I'm not sure exactly what the issue is, but you might want to try using just the element ids in the selectors (make sure the elements you're using have unique ids).
Here's how I've used this in the past:
$('#targetDiv').load('http://localhost/test.aspx #sourceDiv');
Kevin Tighe
2009-03-09 14:08:33
Sure, here it is: $("a.opts").click(function(){ $('<div id="box"></div>').load('my.html div#content', function(){ $(this).appendTo( ".maincontent" ); }); return false; });and in my.html you find <div id="content"> <div id="text" />
2009-03-09 14:40:10
sorry I did not finish the comment... ere is the rest of it:...and in my.html you find <div id="content"> <div id="text" /> <div id="links" /></div>The content of div#text is just some text; the content of div#links# are some <a> elements. I was trying to load them together.
2009-03-09 14:43:17
Hmm. When I've used load() I specified the target element in the $() call like so: $('.maincontent').load(...). Maybe you could try this instead of using the .appendTo call?
Kevin Tighe
2009-03-09 15:04:59
I'll try right now, and let you know. However, wasnt'it supposed to work the same way? (just reversing the order?)
2009-03-09 15:10:24
Thank you SOOOOO much, it's working very well now. Problem solved :)
2009-03-09 15:15:56
Glad to hear it :)
Kevin Tighe
2009-03-09 15:18:56