0

I'm trying to get only the necessary information from a GET request. Here's the function I'm using:

this.updateTargetList = function(content) {
    $.get("index.php?AJAXmd=1", function (data) {
        var selector = "div.list";
        $(selector).html(data);
    });
}

The GET returns a whole bunch of html, more than I need, so it's loading that into the div whose class is "list". For example, the get is returning:

<div class="a">.....
     <div class="b">.......
           <div class="list>........</div>
     </div>
</div>

How can I change data to only get the class or id that I want?

ajw4sk
  • 95
  • 2
  • 13

2 Answers2

0

Answer from Can jQuery Parse HTML Stored in a Variable?

$(myHtml).filter('#someid').doStuff();
Community
  • 1
  • 1
SDekov
  • 9,276
  • 1
  • 20
  • 50
0

There are several ways you can do this. The easiest is to use the load() ajax shorthand method like so. replace #selection with the selector for the part of the DOM you would like to get.

$('div.list').load('index.php?AJAXmd=1 #selection');

You could also get the whole page using $.get or $.ajax and then create a jQuery object from the response and then select the information you want from it.

this.updateTargetList = function(content) {
    $.get("index.php?AJAXmd=1", function (data) {
        var selector = "div.list";
        var data = $(data);
        var selection = data.find('.list').html();
        $(selector).html(selection);
    });
}
Craig Harshbarger
  • 1,863
  • 3
  • 18
  • 29