title: jQuery loop - setTimeout, addClass, removeClass
body: <p>I will be an easy one for JavaScripters. I had a long research but I couldn't find the right answer. I want a menu (basically just anchors and not list elements) to be highlighted like a slider with specific time delay.</p>
  
  <p>Also, it would be nice if you know how to get rid all of these useless ids around using $("#menu a") and $(this). Since I cannot do much JavaScript (although I prefer the simplicity), here is my crappy code in jQuery that works, but it's not looping.</p>
  
  <pre><code>$("#anchor1").addClass("highlight");
  
  function loopMenu() {
      window.clearTimeout();
      setTimeout(function(){$("#anchor1").removeClass("highlight");}, 4000);
      setTimeout(function(){$("#anchor2").addClass("highlight");}, 4000);
      setTimeout(function(){$("#anchor2").removeClass("highlight");}, 8000);
      setTimeout(function(){$("#anchor3").addClass("highlight");}, 8000);
      setTimeout(function(){$("#anchor3").removeClass("highlight");}, 12000);
      setTimeout(function(){$("#anchor4").addClass("highlight");}, 12000);
      setTimeout(function(){$("#anchor4").removeClass("highlight");}, 16000);
      setTimeout(function(){$("#anchor1").addClass("highlight");}, 12000);
  }
  
  loopMenu();
  </code></pre>
  
  <p>What I want: a script that removes Class from current element and addClass to the next anchor type element every 4 seconds and then jump to the first element and repeat it forever.</p>
  
  <p><a href="https://stackoverflow.com/questions/13341945/jquery-addclass-removeclass-with-timer">Here is a solved question</a> that has a few relations to this, although I can't make it work either.</p>