tags:

views:

34

answers:

1

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
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" />
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.
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
I'll try right now, and let you know. However, wasnt'it supposed to work the same way? (just reversing the order?)
Thank you SOOOOO much, it's working very well now. Problem solved :)
Glad to hear it :)
Kevin Tighe