title: Why jQuery.each doesn't loop through all items?
body: <p>Seems like .each function does not loop properly trough all items when there are variable set inside .each function, assuming this as the reason that items do not get removed.
  But 2nd function I've used to test loop shows that it should work.</p>
  
  <p>Any special reasson?</p>
  
  <p>HTML Code:</p>
  
  <pre><code>&lt;div id="top-menu"&gt;
      &lt;ul id="top-menu-main-ul"&gt;
          &lt;li class="top-menu-main-li"&gt;
              &lt;a href="#" title="Home"&gt;Home&lt;/a&gt;
              &lt;div class="arrow-bg-above-ul"&gt; &lt;/div&gt;
              &lt;ul class="top-menu-child-ul"&gt;
                  &lt;li class="top-li-ztyle"&gt;&lt;a class="menu-item-2" href="index.php"&gt;Admin Home&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a class="menu-item-2" href="myaccount.php"&gt;My Account&lt;/a&gt;&lt;/li&gt;
                  &lt;li class="bottom-li-ztyle"&gt;&lt;a class="menu-item-0" href="logout.php"&gt;Logout&lt;/a&gt;&lt;/li&gt;
              &lt;/ul&gt;
          &lt;/li&gt;
  
          &lt;li class="top-menu-main-li"&gt;
              &lt;span class="separator"&gt;&lt;a href="#" title="Clients"&gt;Clients&lt;/a&gt;&lt;/span&gt;
              &lt;div class="arrow-bg-above-ul"&gt; &lt;/div&gt;
              &lt;ul class="top-menu-child-ul"&gt;
                  &lt;li class="top-li-ztyle"&gt;&lt;a class="menu-item-3" href="clients.php"&gt;View/Search Clients&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a class="menu-item-4" href="clientsadd.php"&gt;Add New Client&lt;/a&gt;&lt;/li&gt;
                  &lt;li class="bottom-li-ztyle"&gt;&lt;a class="menu-item-5" href="massmail.php"&gt;Mass Mail Clients&lt;/a&gt;&lt;/li&gt;   
              &lt;/ul&gt;
          &lt;/li&gt;
      &lt;/ul&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>jQuery Code:</p>
  
  <pre><code>var arrayOfitems = ["1","2","33","34","35","36","37","38","39","40","41","42","77"];
  
  $(document).ready(function(){ 
      $(".top-menu-child-ul li a").each(function() {
          var thisClass = $(this).attr('class');
          var thisClassNum = thisClass.replace('menu-item-', '');
          var searchForThisNum = thisClassNum.toString();     
  
          if($.inArray(searchForThisNum, arrayOfitems) !== -1 )
          {
             // do nothing
          }
          else
          {
              $("." + thisClass).closest('.li').remove();
          }
      });
  
  
      // test that loop should work
      var myArray = [];
  
      $(".top-menu-child-ul li a").each(function() {
         myArray.push($(this).attr('class'));
      });
  
      alert(myArray);
  });
  </code></pre>
  
  <p>Fiddle Example:
  - <a href="http://jsfiddle.net/LmUPL/2/" rel="nofollow noreferrer">http://jsfiddle.net/LmUPL/2/</a></p>