Why doesnt Dialog open before each runs?

Why doesnt Dialog open before each runs?

It seems I cant figure out why I cant get a dialog box to open or a div to show/hide before the each function runs... even though I place the open action before the .each function.  

The Show function only runs after the each function is completed. 

How can I get  apDiv1 to show, then the each function works , and when done hides   apDiv1? Thanks in Advance

$('#ApplyM1').click(function() {  
 $('#apDiv1').show();
$('.checkbox1').each(function() { 
         //   my stuff
  }) 
  $('#apDiv1').hide();
 });