I would like my jQuery script to only return ONLY the top node it finds instead of iterating through all the nodes. What do I change in my jQuery script to accomplish that? I know it has to do with the each(function) {} but i don't know exactly what should change. Thanks in advance!
jQuery Code:
$.ajax({
url: 'xml/timeline.xml',
dataType: 'xml',
success: function(data) {
$(data).find('channel item').each(function() {
var fbFeedWrapper = $('<div/>').addClass('fb-feed-wrapper');
var fbFeedItem = $('<div />').addClass('fb-feed-item');
$('.socialmedia-list#simlearn').append(fbFeedWrapper);
fbFeedWrapper.append(fbFeedItem);
var url = $(this).find('link').text();
var title = $(this).find('title').text();
fbFeedItem.append($('<h1/>').html("<a href='" + url + "'>" + title + "</a>"));
var fbItemIcon = $('<div />').addClass('fb-item-icon');
fbFeedItem.append(fbItemIcon);
var description = $(this).find('description').text();
if (description.length > 80) {
description = description.substr(0, 80) + "...";
}
fbFeedItem.append($('<div/>').addClass('fb-item-details').html(description));
})
}
});
XML File format:
<channel>
<item> // <-- If i Only want the top <item> node returned what should i do?
<title></title>
<link></link>
<description></description>
</item>
<item>
<title></title>
<link></link>
<description></description>
</item>
<item>
<title></title>
<link></link>
<description></description>
</item>