Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4623738
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:01:53+00:00 2026-05-22T03:01:53+00:00

I’m having a little problem with the .length() property. I’m trying to count the

  • 0

I’m having a little problem with the .length() property. I’m trying to count the number of spans in each div with a same class. Those Divs are appended previously in the script. The funny thing is, if I alert the variable corresponding to the length, everything works fine, if I remove the alert, it doesn’t. Never seen that 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);
        //alert(nTweets);   
    });


}
tweetCounter();

As I said, it appends correctly when I uncomment the alert. If commented, 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>';
        //alert(tDate);

        var destination = $('#date_'+ tDate +'');
        destination.append(tText);

    });
});

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T03:01:54+00:00Added an answer on May 22, 2026 at 3:01 am

    Based on your comment. It pretty much looks like that the function which adds the .tweet elements does this asyncronously (maybe an ajax-request ?) If that is the case, the method does not block the code execution and again, this would bring your behavior.

    What you would need to do in this case is, provide a callback function to the function which gets and creates the tweets. If that has finished, execute the callback.

    function get_tweets() {
        var requests = [ ];
    
        for(var i = 0; i < 5; i++) {
            requests.push( $.getJSON('/foo' + i + '.json', function(data) {
                // do something and create `.tweet` nodes
            }) );
        }
    
        return requests;
    }
    
    $.when.apply( null, get_tweets() ).done( count_tweets );
    

    This is how it could look like in jQuery 1.5.2+. The get_tweets() function here fires 5 requests and stores the Deferred object in an array which is returned. $.when() will fire when all promises are fulfilled.

    update

    Here is how it should look like with 1.3.2:

    getTweets = function( callback ){
        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(" ");
                // and so forth....
            });
    
            if( typeof callback === 'function' )
                callback();
        });
    }
    

    and then call it like

    getTweets( tweetCounter );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am currently running into a problem where an element is coming back from
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.