﻿function get_rss_feed(elementIdentifier, url, numOfElements) {
    var html = '';
    //use the JQuery get to grab the URL from the item
    jQuery.ajaxSetup({cache: false});
    jQuery.get(url, function(d) {
        //find each 'article' in the file and parse it
        jQuery(d).find('item').each(function(index) {
            if (index >= numOfElements) {
                return false;
            }
            //name the current found item this for this particular loop run
            var $item = jQuery(this);

            // grab the headline
            var title = $item.find('title').text();
            // next, the description
            var description = $item.find('description').text();
            // grab the post's URL
            var link = $item.find('link').text();
            //and the pubdate
            var pubDate = $item.find('pubDate').text();

            //form the link
            html += '<li><a href="';
            html += link + '" target="_blank" >' + title ;
            html += '</a></li>' + "\n";

        });
        //clear the content in the ul each time.
        jQuery(elementIdentifier).empty();
        //put the feed content on the screen.
        jQuery(elementIdentifier).append(html);
    });

};

