ARF
ARF

Reputation: 7694

How do I query the result of xmlhttprequest?

Using xmlhttprequest, how do I query the result using jQuery?

E.g. I am running this code snippet:

$.get('somepage.htm', function(data) {
  console.log($("div.abc").text());
});

Of course $("div.abc").text() is applied to the current page, rather than the page contained in the data variable. How do I fix this and apply $("div.abc").text() to the content of data?

Upvotes: 0

Views: 49

Answers (2)

Friedrich
Friedrich

Reputation: 2290

use the .find() method

 $(data).find("div.abc").text("text");

Upvotes: 1

Quentin
Quentin

Reputation: 943561

Create a jQuery object from the data.

var $data = $(data);

Then manipulate that:

console.log($data.find("div.abc").text())

Upvotes: 1

Related Questions