title: Increment counter unavailable outside of loop
body: <p>I am looping through json return values with jQuery's $.each() and adding the classes returned to their corresponding <code>&lt;div&gt;</code>'s; however the counter appears to be inaccessible for further processing outside of the immediate loop. I have tried using return's &amp; external function calls to no avail. When I alert() the counter inside the iteration, it shows up correctly; and all of the classes update properly. Any insight would be much appreciated.</p>
  
  <p>Code:</p>
  
  <pre><code>var c = 0;
  function refreshIt(){
    var page = $(".navselected").attr('id');
    var ids = $('.content div[id]').map(function(){
      return this.id;
    }).get();
  
    $.ajax({
      type:'POST',
      url:page + 'functions.php',
      data:{'idList[]':ids},
      dataType:'json',
      success:function(data){
        $.each(data,function(element,load){
          $("#" + element).slideUp(400,function(){
            $("#" + element).removeClass("critical ok");
            $("#" + element).addClass(load.status).html(load.number).slideDown(400);
            if(load.status == 'ok'){
              c++;
            }
            else{
              c++;
            }
          });
        });
  
        $('.infostatus').addClass('infook').html("There are " + c  + " errors on this page.     Kudos!");
      }
    });
  }
  </code></pre>