var PLAYLIST_ID = "PLq1Df5yPUOMtaZJsmL_TY5Y1xY12LI6GH"; // YouTube Playlist ID (privacy must be set to "Public") // playlist URL; using jsonp content type because it's cross-domain var PLAYLIST_URL = "http://gdata.youtube.com/feeds/api/playlists/" + PLAYLIST_ID + "?v=2&alt=json-in-script&callback=?"; // on document ready, call loadPlaylist() $(function () { loadPlaylist(); }); function loadPlaylist() { $.getJSON(PLAYLIST_URL, function (plJSON) { // get the playlist feed for (var i = 0; i < plJSON.feed.entry.length; i++) { // loop over video entries var tEntry = plJSON.feed.entry[i]; // video properties var vURL = tEntry.media$group.media$content[0].url; var vTitle = tEntry.media$group.media$title.$t; var vDesc = tEntry.media$group.media$description.$t; // create title and description var vid = $("<h3>"+vTitle+"</h3>"); if(vDesc) vid.after("<p><em>"+vDesc+"</em></p>"); // add videos as iframes vid.after("<iframe width='100%' height='400' src='" + vURL + "'></iframe>"); $("#playlist-container").append(vid); } }); }
<div id="playlist-container"></div>