Does load() retrieve an element with or without its descendants?
Question
I made some tests with the load()
command of jQuery, something like:
$('<div id="box" />').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;
should I call them one by one, with a new load()
statement, or am I doing something wrong?
Solution
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');