adho12
adho12

Reputation: 405

add a jQuery selector to the URL parameter

Is it possible to add a jQuery selector to the URL parameter after an AJAX-request? This is my perfectly working code:

$.ajax({
    type : "POST",
    url : "load_page.php",
    data : 'page=' + url,
    success : function(msg) {
        if (parseInt(msg) != 0)//if no errors
        {
            $content.fadeIn(200, function() {
            $('#content').html(msg);

            });
        }
    }
});
//load the returned html into pageContent 

I know that via .load() (or link) it is possible:

$("# content'").load("demo_test.txt #sub.content");

But is it possible via $('#content').html(msg);?

Additional info: I am trying to only get the <div id=”sub-content”>

Upvotes: 2

Views: 930

Answers (1)

Kevin B
Kevin B

Reputation: 95030

Yes, simply filter the data before appending it.

var $content = $("#content").empty();
$("<div>").html($.parseHTML(msg)).find("#sub").appendTo($content);

Upvotes: 4

Related Questions