Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html anchor works only once

Tags:

html

anchor

I am ashamed to say that I have an anchor issue.

So I have this code:

<a name="map"></a>

$("div.store_list").click(function() {          
    //do some stuff         
    location.href = location.href + '#map'
});

When doing the first click it works fine. And the URL changes to:

http://mydomain.local/stores#map

Second click the URL changes to the following and it doesn't work:

http://mydomain.local/stores#map#map

Any suggestions? Thanks

like image 910
Gabriel Spiteri Avatar asked Oct 18 '25 11:10

Gabriel Spiteri


1 Answers

In case you scroll and need to jump again, this has worked for me:

onclick="location.hash=''; location.hash='#map';"
like image 94
nipo Avatar answered Oct 21 '25 03:10

nipo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!