Reputation: 99
I have some AJAX call like this:
$.ajax({
type: 'GET',
url: <some url>,
dataType: 'html',
success: function(html){
// do some jQuery on the response html
// like this: $('#someDIV').text();
}
});
The response html
likes this:
<html>
<head>
<!-- header things -->
</head>
<div id="someDIV">
content
<div>
</html>
Can I do the query on that response html without append the code to current page?
Upvotes: 3
Views: 1271
Reputation: 6901
var content = $(dynamichtml);
Later, you can query it.
var item = content.select({jqueryCriteria});
Upvotes: 0
Reputation: 115222
Simply wrap by jQuery and do the rest.
var $html = $(html);
Upvotes: 3
Reputation: 9794
Query the response string to find the div element inside it like below
var response = '<html> <head></head> <div id="someDIV"> content <div> </html>'
console.log($(response).find("div"));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Upvotes: 1