why does the top button still link to the top of the page?

54 Views Asked by At

I have a button <a href="#top">Top</a> linking to the top of the page <body id="top"></body> but when removing the id of the body the button still works. I cant work this out, I put it down to the browser cacheing data although I have emptied the cache and re-tried and it still works. This is purely informative, its not causing me any issues.

2

There are 2 best solutions below

2
On BEST ANSWER

I believe if the id does not exist, the browser will handle it the same as '#'. Which links to the start of the page.

1
On

Unrecognised fragment identifiers are treated as being at the top of the document.