views:

73

answers:

1

Is it possible to load multiple items at once through jquery using $.load? For exmaple I may have something like this:

<div id="test">

  <div id="what">
  </div>

  <div id="when">
  </div>

  <div id="who">
  </div>

</div>

Now say I wanted to load the div with the id of what and the id of when but not the who. is this possible?

+1  A: 

If you wanted to load just those two divs into the same container, you would use this:

$("selector").load("/url #what, #when");

You can add any selector after the URL as long as there is a space between the selector and the url.

So with this HTML:

<div id="container"></div>

And this jQuery:

$("#container").load("/url #what, #when");

You would get:

<div id="container">
   <div id="what"> ... </div>
   <div id="when"> ... </div>
</div>
Doug Neiner
thanks that worked but what I was trying to do isnt working. basically I want to take the page i am on "test.php" and load the same exact div into the page without a reload. so it would be $("#mydiv").load("test.php #mydiv"). The problem is that it puts it inside of the other div so it has a second border. Is there a way to just load all the contents of that div or replace it?
ngreenwood6
`$("#mydiv").load("test.php #mydiv > *");` should load all the *children* of "mydiv" into "mydiv", so you don't end up with it inside itself for ever and ever....
Graza