title: Remove anchor from url and history after jquery smooth scroll
body: <p>I have a page for which I've got smooth scrolling anchor links, using jquery 1.10 and <a href="http://www.learningjquery.com/2007/10/improved-animated-scrolling-script-for-same-page-links" rel="nofollow">the code listed below</a>. The smooth scrolling works fine. After clicking the "back to top" link, an item is added to the user's history and visible in the url (as <code>domain.com/page#header</code>), which is expected.</p>
  
  <p>However, because this messes up the url and breaks the functionality of the back button I'm trying to remove the anchor from the url and the browser history. I've tried several methods for removing an anchor link or a history item, but they all cause conflicts with the code for the smooth scrolling.</p>
  
  <p>So my question is, does anyone know how I can remove this anchor from the url and remove the last history item, after the smooth scrolling is done?</p>
  
  <p>An example: <a href="http://jsfiddle.net/CQywc/5/" rel="nofollow">http://jsfiddle.net/CQywc/5/</a></p>
  
  <p><strong>EDIT: I didn't delete this question because it was difficult for me to figure out exactly what I needed to do, even when I saw the answers to the other questions (they address a slightly different issue, and didn't explicitly resolve the added history item). So I'll leave this here for people who have the same problem I had.</strong></p>
  
  <hr>
  
  <p><em>Code for smooth scrolling:</em></p>
  
  <pre><code>$(document).ready(function() {
    function filterPath(string) {
    return string
   .replace(/^\//,'')
   .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
   .replace(/\/$/,'');
    }
    var locationPath = filterPath(location.pathname);
    var scrollElem = scrollableElement('html', 'body');
    $('a[href*=#]').each(function() {
   var thisPath = filterPath(this.pathname) || locationPath;
   if (  locationPath == thisPath
   &amp;&amp; (location.hostname == this.hostname || !this.hostname)
   &amp;&amp; this.hash.replace(/#/,'') ) {
     var $target = $(this.hash), target = this.hash;
     if (target) {
    var targetOffset = $target.offset().top;
    $(this).click(function(event) {
      event.preventDefault();
      $(scrollElem).animate({scrollTop: targetOffset}, 400, function() {
     location.hash = target;
      });
    });
     }
   }
    });
    // use the first element that is "scrollable"
    function scrollableElement(els) {
   for (var i = 0, argLength = arguments.length; i &lt;argLength; i++) {
     var el = arguments[i],
      $scrollElement = $(el);
     if ($scrollElement.scrollTop()&gt; 0) {
    return el;
     } else {
    $scrollElement.scrollTop(1);
    var isScrollable = $scrollElement.scrollTop()&gt; 0;
    $scrollElement.scrollTop(0);
    if (isScrollable) {
      return el;
    }
     }
   }
   return [];
    }
  });
  </code></pre>