views:

64

answers:

2
A: 

Yes, it is possible, but you need to make a jQuery object out of it first.

Change this line:

alert (results.find("div[id='content']").html());

to this:

alert ( $(results).find("div[id='content']").html() );

or, better yet, to this:

alert ( $(results).find("#content").html() );

EDIT:

Looks like if the element you want is a direct child of body, you'll need to use .filter() instead since the body seems to be excluded from the jQuery object. Looks like just its contents are included.

alert ( $(results).filter("#content").html() );
patrick dw
Thanks a ton:) This worked too!
racky
@racky - You're welcome. :o) FYI, using `.find()` is a *tiny* bit faster than `$("#content", results)` since jQuery just converts that into `.find()` anyway. Won't be a noticeable difference, though.
patrick dw
hey thanks again, another tiny issue, now i get the required data with your kind help. what I am now doing is empty the old content from the div [$("#content").empty()] and append the newly retrieved data [.append(newdata)]. But this one strangely reloads the page to a blank page! any thoughts around this?
racky
@racky - Not sure why that would happen. Could you please update your question adding the relevant code at the bottom. Don't change the existing question, otherwise it may confuse things.
patrick dw
@Patrick: The only change is in the success segment of the ajax request:<pre><code>success: function(results){ var $f = $jq(results).find("#content").html(); //alert ($f); $jq("#content").empty().append($f); }</code></pre>
racky
@racky - I assume your alert is showing you the expected data. Your code should work. Check for invalid HTML markup either in the original page, or in the response received. Also, how is the AJAX being triggered? Clicking a link? Submitting a form?
patrick dw
yes. the alert is showing the expected data. I am checking for invalid html. Since the output is huge, I'm not sure i can finish dong that. The ajax is triggered on clicking on a link.
racky
@racky - Since you're clicking a link, did you do `return false` at the end of the click handler for the link? If not, try that and let me know how it goes. :o)
patrick dw
@Patrick, i have tried return false but no luck. something really strange... thanks for the help.... let me know if you have any new ideas:) thanks a lot :)
racky
@racky - Instead of appending the data you receive, try appending something simple, like `<div>test content</div>` and see if that works properly. If it does, then it is most likely some markup issue in the data. I believe there are HTML validators available online that will tell you if your markup is valid.
patrick dw
@patrick, there was problem with the markup and I am fixing it... hopefully that should solve my problem. I really appreciate your time and patience.
racky
@racky - Not a problem. :o)
patrick dw
+1  A: 

what about this?

$("#content", results).html()
yedpodtrzitko
Thanks a ton:) That worked!
racky