开发者

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).fi开发者_如何学JAVAnd("#content"));


Load can use a selector...

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

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


Here is what I would do:

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

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


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');


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜