Im trying to make a twitter feed for my website, however, I want do display 3 of the most recent tweets but in different divs.
I have this code here… I have set up 3 vars with targets to the individual classes where each tweet will be stored.
My main problem is how to store the data for each tweet (i) in the loop. but this is not working… can someone tell me where im going wrong with this? Cheers
$(document).ready(function() {
// Call the Twitter API to retrieve the last 3 tweets in JSON format for the pcpro Twitter account
$.getJSON("http://twitter.com/statuses/user_timeline.json?screen_name=allaboutjames&count=3&callback=?", function(tweetdata) {
var t1 = $("#work-thumbs .tweet-1");
var t2 = $("#work-thumbs .tweet-2");
var t3 = $("#work-thumbs .tweet-3");
// For each item returned in tweetdata
$.each(tweetdata, function(i,tweet) {
// Append the info in li tags to the ul, converting any links to HTML <a href=.. code and convert the tweeted date
// to a more readable Twitter format
t(i).append("<li>“" + urlToLink(tweet.text) + "”– " + relTime(tweet.created_at) + "</li>");
});
});
});
t(i)won’t work. Try this instead:Also notice that jQuery’s
$.each()populatesiwith an indexInArray (beginning with 0).