JQuery – How go to anchor tag without showing hashtag in URL

We use named anchors or # tags to access certain part of  a page like http://www.example.com#middle. Now clicking on this tag will take user to this tag but it will show whole url in address bar.

If we want not to show # url in address bar but want to use named anchors. Use Jquery to accomplish this.

function goToByScroll(id){
    $('html,body').animate({scrollTop: $("#"+id).offset().top},'slow');
}

Just pass the id of the element you wish to scroll to.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.