0

suppose I have a button on www.domain.com linking to a lower part of the page through an anchor tag <a href="#destination">text link</a>

is it possible to prevent the url in url bar of the browser from showing www.domain.com/#destination?

thanks

Peppershaker
  • 101
  • 1
  • 5
  • 2
    Possible duplicate of [append /remove anchor name from current url without refresh](http://stackoverflow.com/questions/5928435/append-remove-anchor-name-from-current-url-without-refresh) – Gonras Karols Apr 13 '17 at 19:50

2 Answers2

0

Use jquery like this:

$("#down").click(function () {
    $('html,body').animate({
        scrollTop: $("#b").offset().top
    });
});

$("#up").click(function ()
    $('html,body').animate({
        scrollTop: $("#a").offset().top
    });
})

Hope this helps.

fiddle:

http://jsfiddle.net/ZGk5F/

Ianardo
  • 69
  • 11
0

You can use this:

$("a.anchor").on("click", function(e) {      
    e.preventDefault();
    $(window).scrollTop($($(this).attr('href')).offset().top);
});
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<a href="#second" class="anchor">Second</a>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<h2 id="second">Second Part</h2>

Now the anchor link shows the address on hover, But scrolls to destination instead of navigation.

Farzin Kanzi
  • 3,220
  • 2
  • 16
  • 21