link to a place in a locally-hosted website

Viewed 40

I'm trying to have my locally-hosted website link to a specific id (inside the website) as follows:

<button onclick="location.href='http://127.0.0.1:5500/#projects'" 
onmouseover="onbutton(this)" onmouseout="offbutton(this)"
type="button">Projects</button>

However, it is not working (the url in my browser changes to 127.0.0.1:5500/#projects when clicked, but the hyperlink does not change which part of the page I'm looking at. I suspect it's because the ip is not a real url. Is there any way I can create a hyperlink to the id projects when my website is being locally hosted?

1 Answers

You could the button inside an <a> tag.

<a href="http://127.0.0.1:5500/#projects"><button
type="button">Projects</button></a>

Related