Reputation: 39
I want to append tweet in an empty div, but when the tweet count is 5 and greater, i want remove one from bottom so that only 5 tweet will appear. i wrote this code which doesnt remove anything
var side = 'left';
cnt = 0;
setInterval(function(){
$('.tweet-stream').prepend('<div class="tweet t'+side+'"></div><div class="t-header"></div>');
if(cnt%2==0){
side='right';
} else {
side='left';
if(cnt>=5){
$("div[class=tweet]:last").remove();
}
}
cnt++;
},3000);
Upvotes: 0
Views: 101
Reputation: 135
Looks like you were only removing the last tween when the "left" condition was met.
This seems to be working:
http://jsfiddle.net/chace/dgv8U/10/
var side = 'left';
cnt = 0;
setInterval(function () {
$(".tweet-stream").prepend("<div class='tweet t" + side + "></div><div class='t-header'>tweet-" + cnt + "</div>");
if (cnt % 2 == 0) {
side = 'right';
} else {
side = 'left';
}
if (cnt >= 5) {
$("div.tweet:last").remove();
}
cnt++;
}, 3000);
Upvotes: 2