At the moment I have integrated Last.fm API on my site www.midnightlisteners.com but it puts all the Last.fm data on the last one Kanye West. If you hover over the ( i ) icon you will see the data comes up in a tool-tip.
I would like to loop through all and add them in the corresponding place. Plus it would be great If someone could help me get the small artist images too.
My jQUery code:
$(document).ready(function() {
// Find Related Artists based on Last.fm JSON Results
$(".artist-data").each(function() {
// Find the artist name in the "p" tag and save it
artistName = $(this).find(".artist-wrap-mid p");
artist = artistName.text();
// Create a class out of the artist name made of lowercase letters and "-" instead of spaces
artistClass = artist.toLowerCase().replace(/ /g, '-');
// Add this class to the .artist-data div
$(this).addClass(artistClass);
// Check if a value is present
if (artist === '') {
$("." + artistClass + " .related").html("No related artist info found for " + artist);
}
// Otherwise return the request with links to each related artist
else {
$.getJSON("http://ws.audioscrobbler.com/2.0/?method=artist.getsimilar&artist=" + artist + "&api_key=9c991c10bf461ac4e4f92fdfa14c20c2&limit=3&format=json&callback=?", function(data) {
var html = '';
$.each(data.similarartists.artist, function(i, item) {
html += "<a href='http://" + item.url + "' target='_blank'>" + item.name + "</a>, ";
}); // End each
$("." + artistClass + " .related").append(html);
}); // End getJSON
} // End Else
});
});
My HTML is best seen in my website: www.midnightlisteners.com
But it puts all the data from Last.fm in to <div class="related"> </div>
I have gotten a ton of help here: writing.sackettsolutions.com/2012/02/navigating-the-last-fm-api-with-a-little-help-from-jquery-getjson