Loop through only five times on XML Success
I have my code written that returns a list of all the items from my XML list. I want to just show the most recent five items based on the <pubDate> which looks like this:
- <pubDate>Mon, 08 Apr 2013 15:21:26 GMT</pubDate>
The code that I have that works is this but I don't know how to read the pubDate and only show the 5 most recent items.
- <script type="text/javascript">
$(document).ready(function(){
$.ajax({
type: "GET",
url: "/feeds/rss/news-feed-2/",
dataType: "xml",
success: function(xml) {
$(xml).find('item').each(function(){
var title = $(this).find('title').text();
var link = $(this).find('link').text();
var date = $(this).find('pubDate').text();
$('<li></li>').html('<a href="'+link+'">'+title+'</a>').appendTo("#news");
});
}
});
});
</script>