0

I would like to make a $.get request that, upon responding, modifies the DOM at a specific index. So for example, replacing all the IDs in a DOM by their titles by iteratively making $.get requests, it looks like:

$(".findme").each(function() {
  // I want to replace ID inside findme with a title.
  id = $(this).text();
  index = $(this).attr("id");

  $.get(url + "/" + id, function(data) {
    // This doesn't work because $(this) is no longer the same
    // as the one scoped to .findme
    $(this).text(data.title);               
  });
  $(this).removeClass("findme");
});

So that

 <div class="findme" id="1">123432</div>
 <div class="findme" id="2">432411</div>

can become

 <div>Here's a fancy title</div>
 <div>Here's a different title</div>

How does one go about doing this? For convenience, imagine each of the divs have indexes like the above that can be retrieved as well and used.

Rio
  • 14,182
  • 21
  • 67
  • 107

0 Answers0