I have a little problem with the .length () property. I am trying to count the number of spans in each div with one class. These divs are added earlier in the script. The funny thing is, if I warn the variable corresponding to the length, everything works fine, if I remove the warning, it is not. I've never seen this before, so any help would be appreciated :) Here is the code:
getTweets();
tweetCounter = function(){
$('.entry').each(function(){
var nTweets = $('.tweet', this).length;
var infoPane = $('.infoPane', this);
var tLink = '<a href="#" class="tLink" title="Tweets of the day">' + nTweets + ' Tweets that day</a>';
infoPane.append(tLink);
});
}
tweetCounter();
As I said, he correctly adds when I uncomment the warning. If you comment, 0 is displayed on every DIV ... Any ideas?
Here's the getTweets function:
getTweets = function(){
var url = "http://twitter.com/status/user_timeline/charleshaa.json?count=30&callback=?";
$.getJSON(url, function(data){
$.each(data, function(i, item) {
var fullTDate = item.created_at;
var splitTDate = fullTDate.split(" ");
var tMonth = splitTDate[1];
if (tMonth == "Jan"){
tMonth = "01"
} else if(tMonth == "Feb"){
tMonth = "02"
} else if(tMonth == "Mar"){
tMonth = "03"
} else if(tMonth == "Apr"){
tMonth = "04"
} else if(tMonth == "May"){
tMonth = "05"
} else if(tMonth == "Jun"){
tMonth = "06"
} else if(tMonth == "Jul"){
tMonth = "07"
} else if(tMonth == "Aug"){
tMonth = "08"
} else if(tMonth == "Sep"){
tMonth = "09"
} else if(tMonth == "Oct"){
tMonth = "10"
} else if(tMonth == "Nov"){
tMonth = "11"
} else if(tMonth == "Dec"){
tMonth = "12"
}
var tDay = splitTDate[2];
var tYear = splitTDate[5];
var tDate = tDay + '-' + tMonth + '-' + tYear;
var tText = '<span class="tweet">' + item.text + '</span>';
var destination = $('#date_'+ tDate +'');
destination.append(tText);
});
});
}
source
share