user1765637
user1765637

Reputation:

jQuery order for 2 methods to be executed when document ready

I have this situation.

$(document).ready(function(){ 
    $.each(elements,do());
});

I would like to execute another new method after the $.each() has finished new method called doOther().

Where I can set my new method for example doOther(); ? I have new $.each inside new method just for info.

Update

This is my script

$(function(){
    $.each($('.countdown'), function() {
        var _element = '.countdown-'+$(this).attr("id");
        if ($(_element).length > 0) {
            var _expDate = $(_element).attr('data-expiration').split(',');
            _expDate.forEach(function(v,i,a){a[i]=parseInt(a[i]);});
            var _datetime = new Date(_expDate[0],_expDate[1],_expDate[2],_expDate[3],_expDate[4],_expDate[5]);
            init_countdown(_element,_datetime);
        }
    });

    $.each($('.countdown'),function() {
        var ips = $(this).text().split(',');
        $(this).html('<div class="span12">'+ips[0]+'</div>');
    }); 
});

function init_countdown(_element,_datetime){
    $(_element).countdown({
        date: _datetime /*"June 7, 2087 15:03:26"*/
    });
}

it seems that $.each($('.countdown') etc.. is overridden by the first $.each, can't understand why.

Upvotes: 0

Views: 60

Answers (3)

Vivek S
Vivek S

Reputation: 5540

This should do it,

$(document).ready( function(){ 
 $.each(elements,do());
 doOther();
} );

Upvotes: 1

Rory McCrossan
Rory McCrossan

Reputation: 337560

If I've understood what you mean, your code should look like this:

$(document).ready(function(){ 
    $.each(elements, do);
    doOther();
});

If this isn't what you meant, please edit your original question and add more detail.

Upvotes: 3

Sergio
Sergio

Reputation: 6948

Implement another method right after your first $.each block

Upvotes: 0

Related Questions