jQuery get and displaying html results

49 Views Asked by At

I have the following jQuery get:

$.get("rssread.cfm?number=10", function (d) {
  $('#feedContent').append($(d).html());
});

The get works fine and what it returns is some html of unordered lists and their items and anchor tags. No big deal. I know that the html is there and properly formed because I can do

$(d).find("ul li a").each(function (i) {
  alert("text: " + $(this).text());
  alert("href: " + $(this).attr('href'));
});

and see the data in the tags (by the alert). However, I really would like to view all of the HTML in $(d) so that I can do some testing, but for the life of me I cannot figure out how to put the contents of $(d) into the div or a span tag!!

The div tag is simply:

<div id="feedContent">
</div>

And this is the part that doesn't work (as seen at the very top of my post) that I expect would (the div comes up empty every time even though I know that $(d) contains the html.

$('#feedContent').append($(d).html());

Thanks for any help in advance!

2

There are 2 best solutions below

0
On BEST ANSWER

Try simply doing this, if you're sure html is returned.

$('#feedContent').append( d );
0
On

The data returned by the get is basically just a (html)string.

Just append it (don't try to create a jQuery object with it).

Change:

$('#feedContent').append($(d).html());

To:

$('#feedContent').append(d);