Search code examples
phphtmlhref

HTML href="#" in php


In HTML you can write href="#" to prevent a page reload, however in php this doesn't appear to work. Is there an alternative?

It adds # to the existing url, but that's not what I want. I also don't want to remove the href since it replaces the cursor with a select text cursor, and I don't really want to be changing my css for what should be basic php.

I'm sure im just doing something wrong anyway. Thanks!


Solution

  • By using a hash you're attempting to tell the browser to navigate to an anchor on the page. If you want to cancel the default behavior and not modify your CSS simply void the anchor's behavior with Javascript:

    <a href="javascript:void(0)">...</a>
    

    There's a very good description of what this does and why you would use it here: What does "javascript:void(0)" mean?