Displaying feed images via jQuery
I am trying to pull in some properties via jQuery from a feed, for instance,
http://feeds.nationalgeographic.com/ng/News/News_Main
I am currently using the following code:
function OnLoad() {
var mcFeed = new google.feeds.Feed("http://news.nationalgeographic.com/index.rss");
mcFeed.setNumEntries(5);
mcFeed.load(function(result) {
if (!result.error) {
var container = document.getElementById("feed");
for (var i = 0; i < result.feed.entries.length; i++) {
var entry = result.feed.entries[i];
var attributes = ["title", "link"];
for (var j = 0; j < attributes.length; j++)
{
开发者_StackOverflow var div = document.createElement("div");
div.appendChild(document.createTextNode(entry[attributes[j]]));
container.appendChild(div);
}
}
}
});
}
google.setOnLoadCallback(OnLoad);
This displays the two properties in plain text; however, I want to display the associated image. It has the <media:content>
tag. I'm new to working with feeds and I'm confused as how to access these nested tags.
Thanks for any suggestions!
Have you tried using child or descendant selectors? In JQuery you can usually do stuff like $( "div media:content" ).whatever()
or $( "div > media:content" ).whatever()
, where the preceding word is the parent tag. Conversely, you could insert classes or ids into these child tags if there is a way to do it, and then target those.
精彩评论