tags:

views:

16

answers:

1

Consider this ajax call:

$.ajax({
    type: "POST",
    url: "misc/moreactivities.php",
    data: { lastmsg : ID, pid: pid },  
    cache: false,
    success: function(html){
        $("#profileWall").append(html);
        $("#more"+ID).remove();
    }
});

Right now it appends everything that is output in moreactivities.php. I only want to append the div#moreactivity element from within it.

How can this be done?

+1  A: 

You can use the html that's returned as the context for a #moreactivity selector, like this:

$.ajax({
  type: "POST",
  url: "misc/moreactivities.php",
  data: { lastmsg : ID, pid: pid },  
  cache: false,
  success: function(html){
    $("#moreactivity", html).appendTo("#profileWall");
    $("#more"+ID).remove();
  }
});

Instead of appending all the HTML, this looks for the #moreactivity element inside it and appends that to #profileWall.

Nick Craver
Hello. the #more removes, and nothing appends to #profileWall.
Karem
@Karem - can you clarify a bit? are you sure there's a `id="moreactivity"` in the response?
Nick Craver
Doublechecked. There is id="moreactivity" in the response.
Karem