Home > Blockchain >  jquery: find not working w.r.t the html response from a ajax request
jquery: find not working w.r.t the html response from a ajax request

Time:10-29

I am trying to get html web page using ajax and then try to find a specific div

$.get(url, function (data) {
 console.log($(data).find("div#container").html());
});

While debugging I see $(data) in console as

>> $(data)
Object { 0: #text, 1: title, 2: #text, 3: link, 4: #text, 5: link, 6: #text, 7: meta, 8: #text, 9: meta, … }

If i expand I can see

enter image description here

But when I check

>> $(data).find("div#container")
Object { length: 0, prevObject: {…}, context: undefined, selector: "div#container" }

How can I get that element from $(data)

CodePudding user response:

From the look of the HTML output in the image, there is no root element to find() from. As such, use filter() instead:

$.get(url, function (data) {
  console.log($(data).filter("#container").html());
});
  • Related