2

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”>

1
  • 1
    The "/your/url #selector" syntax only works in .load(). Commented Aug 26, 2013 at 18:29

1 Answer 1

4

Yes, simply filter the data before appending it.

var $content = $("#content").empty();
$("<div>").html($.parseHTML(msg)).find("#sub").appendTo($content);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.