As jQuery parses this html the output will contain three elements: title, meta, and the div instead of the single html. So .find() won't work because it will search in the descendant elements, but filter will return '#a' because it's an element of the current jQuery object.
$('<html></html>') doesn't work either, I guess it's not possible to create an html element so easily. You can also try setting the dataType option to html (or maybe xml). On Jan 11, 11:13 am, "David .Wu" <chan1...@gmail.com> wrote: > I tried all your suggestion, but got some weired result. > > ajax.html > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> > <html xmlns="http://www.w3.org/1999/xhtml"> > <head> > <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> > <title>ajax</title> > <script type="text/javascript" src="js/jquery-1.2.6.js"></script> > </head> > > <body> > <div id="response"></div> > <input name="btn" type="button" value="ajax" id="btn" /> > <script language="javascript"> > <!-- > $(document).ready(function() > { > $('#btn').click(function() > { > $.ajax( > { > url:'ajax.php', > cache:false, > success:function(res) > { > > $('#response').html($('#a',res).text()); //got nothing > $('#response').html($(res + ' > #a').text()); //got ajaxtest > contents > > $('#response').html($(res).find('#a').text()); //got nothing > } > }); > }); > }); > //--> > </script> > </body> > </html> > > ajax.php > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> > <html xmlns="http://www.w3.org/1999/xhtml"> > <head> > <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> > <title>ajax</title> > </head> > > <body> > <div id="a">test contents</div> > </body> > </html> > > On 1月10日, 上午2時11分, dropcube <ronnyh...@gmail.com> wrote: > > > > is there any way to get the value 123 straight from div? > > > yes, just apply a jQuery selector to the response content and get > > whatever you need. In this example: > > > $('#a', res).text(); > > > OR > > > $(res).find('#a').text(); > > > You can also try with $.load that allows you to specify a jQuery > > selector in the URL.