I want to select a particular Div after calling a php using $.ajax:
my PHP file produce a HTML like following :
<html><head></head><body>
<div id="res_num">123</div>
</body></html>
and in another file I can load the above html and attach it to my current HTML but I want to get the “123” not the whole HTML for this matter I’ve written something like :
var param = "ID=1";
$.ajax({
type: "GET",
url: "latest.php",
data: param, //with the page number as a parameter
dataType: "html", //expect html to be returned
success: function(msg){
if(parseInt(msg)!=0) //if no errors
{
$('#result').html(msg);
//below line works !!!
var handle = $(msg).html(); //filter("div.num_result").html();
/following line doens't help me even changing it with .find doesn't help me
var myDiv = $(handle).filter("div.res_num");
alert(handle.html());
}
}
How can I get only a portion of a html using jquery selector and ajax?
There is a function
.loadthat provides this functionality, namely:However,
.loadconstrains you heavily on what you can do with the filtered HTML: it places it inside an existing element and that’s that. If that’s too restrictive then you will have to modify what your code on the server side returns (although from your example it looks like it would work in this case).