title: For Loop Javascript ScrollTo.Document Items not Working after refactor
body: <p>I've tried to refactor a list of 10 blocks of javascript code into a for loop. It was previously working when they were seperate however I can't seem to see what I'm doing wrong.</p>
  <p>Previously I had 10 blocks like the two below.</p>
  <pre><code>$(&quot;#browse-loan-types-btn&quot;).click(function () {
    $([document.documentElement, document.body]).animate({
      scrollTop: $(&quot;#browse-loan-types&quot;).offset().top
    }, 600);
  });
  
  $(&quot;#versus-btn&quot;).click(function () {
    $([document.documentElement, document.body]).animate({
      scrollTop: $(&quot;#versus&quot;).offset().top
    }, 600);
  });
  </code></pre>
  <p>Then I refactored to this however the scroll functionality isn't working. Does anyone have any ideas?</p>
  <pre><code>const links = [&quot;browse-loan-types&quot;, &quot;versus&quot;, &quot;blog-posts&quot;, &quot;business-advice&quot;, &quot;how-to-get&quot;, &quot;types-of-small&quot;, &quot;loan-options&quot;, &quot;loan requirements&quot;, &quot;how-to-apply&quot;, &quot;increase-odds&quot;]
  
  $(document).ready(function () {
    for (var i = 0; i &lt; links.length; i++) {
  
      $(&quot;#&quot; + links[i] + &quot;-btn&quot;).click(function () {
        $([document.documentElement, document.body]).animate({
          scrollTop: $(&quot;#&quot; + links[i]).offset().top
        }, 600);
      });
    }
  })
  </code></pre>