Scroll to id hash name update in url bar just in scroll

Example: when it is in section got id1
and #id2 for section got id2 so its update instantly in browser url bar.

$("a").on('click', function(event) {

    // Make sure this.hash has a value before overriding default behavior
    if (this.hash !== "") {
      // Prevent default anchor click behavior

      // Store hash
      var hash = this.hash;

      // Using jQuery's animate() method to add smooth page scroll
      // The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area
      $('html, body').animate({
        scrollTop: $(hash).offset().top
      }, 800, function(){
        // Add hash (#) to URL when done scrolling (default click behavior)
        window.location.hash = hash;
    } // End if

Demo what i mean url:


I do not understand what you are expecting your code to do. Can you elaborate on what you are trying to do and then explain what happens instead?

Also, as usual, if you can provide a link to the existing code you are working on for this project, it will help us be on the same page.