1
<a href="#get1"><button type="button" class="btn btn-outline-info btn-sm">GET</button></a>

So I have a number of these anchors on multiple pages. They don't link to another page just scroll the user to the section with the same ID.

When clicked it adds '#get1' to the url, is there anyway to remove/disable this feature?

Kyle
  • 667
  • 6
  • 28

1 Answers1

5

Yes, by hijacking it with jQuery (or plain JS, but you have a jQuery tag). On the click you prevent the actual event (so the anchor never works like a default anchor, eg: dont change location) and then do any scroll actions with javascript.

$('.example').on('click', function(e){
    e.preventDefault();
    const elem = this; // save it so we can use it in the animate

    $('html, body').animate({
        scrollTop: $( $(elem).attr('href') ).offset().top
     }, 2000);
});

In my example, I'm assuming that you have "#example" in the href, and a matching ID. If you want more complex selections, you should change the attr('href') part to eg a data() attribute

Martijn
  • 15,791
  • 4
  • 36
  • 68