I have the following code:
$.post(
url,
send_to,
function(data) {
console.log($(data).find("img");
}
);
I’m getting some result from server and want to find the src value of img tag in that result HTML code, but it’s not working.
How I can search for the img tag in the received data?
Your code should work fine. The jQuery function (
$(data)) will turn a valid HTML string into a (decoupled) Node tree.Be aware, though, that
find()searches through the descendants of the element or collection of elements on which it is called. If your<img>is in the top level of the HTML, usefilter()instead. For example:If the
<img>is not in the top level, make sure the data that is returned is valid HTML and contains an<img>in the first place.