Parse First Title from RSS with jQuery

94 views Asked by At

I don't want to parse all title from the list. I only want the first title to be parsed. Any suggestion?

    function parseRSS(url, container) {
  $.ajax({
    url: document.location.protocol + '//ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=10&callback=?&q=' + encodeURIComponent(url),
    dataType: 'json',
    success: function(data) {

      $.each(data.responseData.feed.entries, function(key, value){
        var thehtml = '<h3><a href="'+value.link+'" target="_blank">'+capitaliseFeed(value.title)+'</a></h3>';
        $(container).append(thehtml);
      });
    }
  });
}


function capitaliseFeed(string) {
    return string.toUpperCase();
}
1

There are 1 answers

0
janih On

Instead of $.each you could loop the data and keep only the first entry

for (var i = 0; i < data.responseData.feed.entries.length; i++) {
    var entry = data.responseData.feed.entries[i];
    var thehtml = '<h3><a href="'+entry.link+'" target="_blank">'+capitaliseFeed(entry.title)+'</a></h3>';
    $(container).append(thehtml);
    break;                                                      
}