wait until certain code is run
<p>This is a continuation from this post - <a href="http://stackoverflow.com/questions/13946058/visible-selector-issue">:visible selector issue</a></p>

<p>Anyway, I was wondering if there is a way to detect if a particular code segment is run until it is completed before running a new line of code.</p>

<p>For example,</p>

<pre><code>if(filterVal == 'all') {  
    jQuery('ul#portfolio li.hidden').fadeIn('slow').removeClass('hidden');  
} else {  
    jQuery('ul#portfolio li').each(function() {  
        if(!jQuery(this).hasClass(filterVal)) {  
            jQuery(this).fadeOut('normal').addClass('hidden');  
        } else {  
            jQuery(this).fadeIn('slow').removeClass('hidden');  
        }  
    });  
} 
</code></pre>

<p>What I want to do is make sure that all the list-item elements are successfully fadeIn(display:block) and fadeOut(display:none) successfully before triggering the jPages function to create pagination.</p>
