Eli
Eli

Reputation: 4359

load a specific element from an ajax loaded page

So...um, how can I load a specific DIV from a page loaded via ajax?

I have this working

$.get(url,function(content){
    //ajax content here

});

there is a div called #content from the page being loaded. I want to load that div into my div called #wrap on the main page.

I was thinking something like this maybe

$("#wrap").load($(content).find("#content"));

Upvotes: 1

Views: 7578

Answers (4)

DefyGravity
DefyGravity

Reputation: 6011

$("#wrap").load(url + " #content", data, function(text, data, xhr){alert("success!");});

Upvotes: 0

Jess
Jess

Reputation: 8700

Here is what I would do:

$.post('THE LINK',
    function(data)
    {
        $('#wrap').html($(data).select('#content').html());
    }
);

The fiddle: http://jsfiddle.net/mazzzzz/P77Ev/

Upvotes: 2

no.good.at.coding
no.good.at.coding

Reputation: 20371

jQuery.load() already does that for you (look under 'Loading Page Fragments'). In your case, get rid of the call to $.get() and use the following instead:

$("#wrap").load(url + ' #content');

Upvotes: 0

jbrookover
jbrookover

Reputation: 5150

Load can use a selector...

$('#wrap').load('ajax/test.html #container');

Pulled directly from the jQuery Documentation: http://api.jquery.com/load/

Upvotes: 5

Related Questions