0

I found a weird behaviour of <a href='url'> and I'm not able to understand why it acts in this way.

This is a little snippet in order to make everything as clear as possible:

<a class="nav-link" href="index.html"><button type="button" class="btn btn-secondary">Home</button></a>

<a class="nav-link" href="index.html#anchor"><button type="button" class="btn btn-secondary">click me</button></a>

So the first link refresh the page, while the second one just skips to the anchor without reloading the page. Why? I'm not getting it and I cannot find anything online.

halfer
  • 19,824
  • 17
  • 99
  • 186
Simo
  • 955
  • 8
  • 18

1 Answers1

1

It's not a weird behavior, it's the actual behavior.

A fragment identifier is used to point at some place in the current DOM, so the browser is not reloading because you are saying to it to go to somewhere in the current page. If you want to force it to reload I suggest you to read this question.