title: Highlight Menu Item when Scrolling Down to Section
body: <p>I know this question have been asked a million times on this forum, but none of the articles helped me reach a solution.</p>
  
  <p>I made a little piece of jquery code that highlights the hash-link when you scroll down to the section with the same id as in the hash-link.</p>
  
  <pre><code>$(window).scroll(function() {
      var position = $(this).scrollTop();
  
      $('.section').each(function() {
          var target = $(this).offset().top;
          var id = $(this).attr('id');
  
          if (position &gt;= target) {
              $('#navigation &gt; ul &gt; li &gt; a').attr('href', id).addClass('active');
          }
      });
  });
  </code></pre>
  
  <p>The problem now is that it highlights all of the hash-links instead of just the one that the section has a relation to. Can anyone point out the mistake, or is it something that I forgot?</p>