views:

90

answers:

1

Does anyone know if it's possible to load a specific div from a variable like

$item = '#help_mobiel_prive';

$('#infopopup_content').load('help.html'+ $item, function() {

only that one doesn't work

+2  A: 

I'm guessing that what you mean to do is something like this:

var $item = '#myDiv';
$("#infopopup_content").load('help.html ' + $item, function() {
    //blah blah
);

Make sure there's a space between the file you're trying to load, and the selector. So instead of:

load('help.html' + $item...

Use:

load('help.html ' + $item...

So the concatenated string would be 'help.html #myDiv'.

From the docs:

In jQuery 1.2 you can now specify a jQuery selector in the URL. Doing so will filter the incoming HTML document, only injecting the elements that match the selector. The syntax looks something like "url #some > selector". Default selector "body>*" always applies. If the URL contains a space it should be escape()d. See the examples for more information.

karim79
yes, but instead for #myDiv use a variable like $itemthat would save me off putting the load function in every else if statement
As long as item contains a valid jQuery selector. I've edited the answer.
karim79
LOL, which is now almost the same as your question, so YES, the answer is YES :)
karim79
Try leaving a space after 'help.html', like .load('help.html ' ...
karim79
No Richard, like this: 'help.html '+$item; That will create a string like: 'help.html #myDiv' if the value of $item = '#myDiv' ($item has to be a string, it cannot be a jQuery object or array or whatever)
Pim Jager
Karim,Pim thanks I put a space between the first quotesI did not imediately catch(or see) what you where trying to say So it will come out as somefile[space]#somediv
Thanks Pim, I had to do some day job stuff. Richard, does that work now?
karim79