Search code examples
javascripthtmlhrefplaceholder

Why use `javascript:void(0)` instead of `javascript:` as an href do nothing placeholder?


I have seen href="javascript:void(0)" and I have seen href="javascript:;" Is there any reason I would not just use href="javascript:" instead?

Edit: Let me make it clear: I am combining this with an onclick and have no objection to using return false if it becomes necessary to use the alternative. Of course this is only if the alternative makes better sense over javascript:.

Also, I have yet to see a answer to my question shown (clearly I think) in the first paragraph. Thanks, david. :)

I have seen href="javascript:void(0)" and I have seen href="javascript:;" Is there any reason I would not just use href="javascript:" instead?


Solution

  • Doesn't answer you question but may shed a bit more light on it, some early versions of browsers like netscape had problems when a script was used within the href.

    The void operator was pretty much to only way force the click to do nothing.

    Now, with browsers properly implementing "pseudo URLs", you can safely just use javascript:;.