Hi Grimace,

You should get what you're trying to find by wrapping value in a <div>. Try this inside the success callback:

   var $value = $('<div> + value + '</div>');
   var body = $value.find('body');
   var form = $value.find('form');
   var p = $value.find('p'); // Actual paragraphs


--Karl

____________
Karl Swedberg
www.englishrules.com
www.learningjquery.com




On Sep 24, 2009, at 8:01 AM, Grimace of Despair wrote:


Working on WinXP in FireFox 3.0.14 with JQuery 1.3.2, I'm trying the
following code:

$.ajax({
 url: "http://foo.bar/document";
 data: 'r=' + Math.random(),
 success: function(value) {

   var body = $(value).find('body'); // Always empty
   var form = $(value).find('form'); // Always empty
   var p = $(value).find('p'); // Actual paragraphs

 }
});

Now, "body" and "form" are always empty, while "p" contains actual
paragraphs.

When I debug $(value) with Firebug, I see that it has become an array
with some text nodes (whitespace), some link nodes (css) and a form
node. The form node contains script nodes (although in the html, they
occur in the head) and the content html.

Now I'd like "body" and "form" to contain their respective counterpart
from the newly loaded content, but, aside from doing some custom
implementation, can I do that with JQuery in some way with a find?
Obviously, the current find on body/form does not work, because it's
applied iteratively on the array and it cannot find top-level element.
The find('p') does work because they are not top-level within an array
node.

Regards,

Grimace

Reply via email to