Reputation: 1
I made an ajax call to a page and I receive some HTML code:
$.ajax({
url: 'test.php',
data: "id=1",
cache: false,
success: function(myHtml){
//here I have myHtml
}
});
the returned html by test.php is myHtml and looks like:
<div id="firstDiv">
some text 123
</div>
<div id="firstDiv">
some text 456
</div>
How I get the content of firstDiv in jquery success ?
Thank you.
Upvotes: 0
Views: 84
Reputation: 237837
You can use the jQuery constructor to build a jQuery object based on that code.
var results = $(myHtml);
In this case, you will have several elements in the selection, so you'll need to filter them, perhaps with eq
in this case:
var firstResult = results.eq(0);
Note that there is no telling what jQuery will do with multiple instances of the same id
in an HTML string.
Upvotes: 1