jQuery each callback

NoNameZ picture NoNameZ · Sep 4, 2012 · Viewed 40.5k times · Source

How to use callbacks on jQuery each function?

I am trying something like:

$.each(images, function(key, value) { 
    new_images+= '<li><a href="'+value+'"><img src="'+value+'" alt="'+[key]+'" /></a></li>';
}, function (){
    $('#Gallery').remove();
    $('body').append('<ul class="gallery">'+new_images+'</ul>');
});

Answer

Damian SIlvera picture Damian SIlvera · Sep 4, 2012

$.each(); is a synchronous function. That means you don't need a callback function inside because any code you write after $.each(); will run affter $.each(); ends.