 <p>Better to cache $('html, 'body') before scrolling and use event delegation.</p> <pre><code>var $htmlBody = $('html, body'); $htmlBody.on('click', '.services-nav li a', function() { var target = $(this).attr('href') var offsetTop = $(target).offset().top || 0; $htmlBody.animate({scrollTop: offsetTop}, 1500); return false; }); </code></pre>