Bandydan
Bandydan

Reputation: 631

Taking part of ajax response with jQuery.filter fails

The code below is not working. It receives html with appropriate div with class="filtered_entries_box". The problem is filtering.

$.ajax({
    "url" : "start.php",
    "type" : "POST",
    "data" : "action=entries",
    "dataType" : "html",
    "success" : function(data) {
        var filtered_entries_box = $($(data).filter(".filtered_entries_box")[0]).html();
        $(".filtered_entries_box").html(filtered_entries_box);
    }
});

I have tried it with another div, and it worked. The only difference between them is that second one is much closer to <body>, so maybe filter can not work with a deep DOM objects?

....
"success" : function(data) {
    var contentDiv = $($(data).filter(".container")[0]).html();
    $(".container").html(contentDiv);
}
....

My html:

<div class="container">
    <div class="top_bar">
    ...
    </div>
    <div id="new_entry_box">
    ...
    </div>
    <div class="filtered_entries_box">
    ...

Can filter work with that or not? Appreciate any advices.

Upvotes: 0

Views: 2119

Answers (1)

Jason P
Jason P

Reputation: 27012

I would do this:

var html = $('.filtered_entries_box', data).html();

Upvotes: 1

Related Questions