0

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();
}
0

1 Answer 1

1

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;                                                      
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.