title: jQuery.each and setTimeout don't play together well (possibly)?
body: <p>So, I read a lot about the issue. Nothing I was able to find online resolved my problem. Here is a bit of code:</p>
  
  <pre><code>jQuery( 'input:not([type=submit]):not([type=hidden]), textarea' ).on( 'click', function() {
  
      $this = jQuery( this );
      parentWrap = $this.parents( 'label' );
      inputLabel = parentWrap.find( '.label' );
      otherInput = jQuery( 'input:not([type=submit]):not([type=hidden]), textarea' ).not( this );
  
      if ( ! parentWrap.is( '.focused' ) ) {
          parentWrap.addClass( 'focused' );
          setTimeout( function() {
              inputLabel.addClass( 'focused' );
          }, 1000 );
      }
  
      otherInput.each( function( index, elem ) {
          elem = jQuery( elem );
          elemVal = elem.val();
          elemParentWrap = elem.parents( 'label' );
          elemInputLabel = elemParentWrap.find( '.label' );
          if ( elemParentWrap.is( '.focused' ) ) {
              if ( 0 === jQuery.trim( elemVal ).length ) {
                  elemParentWrap.removeClass( 'focused' );
                  setTimeout( function() {
                      elemInputLabel.removeClass( 'focused' );
                  }, 1000 );
              }
          }
      });
  });
  </code></pre>
  
  <p>The process:</p>
  
  <ol>
  <li>I click the input, two elements related to that input have <code>.focused</code> classes added. One of those classes is added with delay.</li>
  <li>Second part of the function goes through every input on page, except
  of the clicked one, checking, if its elements got class <code>.focused</code>. When no class found it doesn't execute anything.</li>
  <li>I click another input on the same page, it goes through point 1. everything works ok. Every two elements (<code>label</code> and <code>.label</code>) related to any other input (other than the one clicked) are supposed to have their class <code>.focused</code> removed, (one of those related elements to have class removed with delay), but removing with delay doesn't happen.</li>
  </ol>
  
  <p>How to sort it out?</p>
  
  <p>PS, hope I put everything clear. If not please ask a question. There is also small input value check in the code. Please ignore it as it's not relevant for the question.</p>
  
  <p>PS2, when I remove timeout from second function both elements related to the input have their classes removed.</p>