In the following example, I want to summon #b if #a is missing and vice versa. How can I do that using same anchor tag? The code is for the same page. The following code doesn't work anymore.
I tried this and result is that both the onclick and href are "executed": just have a look in your browsers history. One step back you'll find thepage with #b and two steps back the page before the click.
Let's take a step back, and please explain how #a could be "missing". If this is a static HTML page, then the contents are well-known and there's no need for a fallback. If it's a generated page where #a is dynamically generated based upon a condition, that same condition can be used to correctly target the link. Rather than trying to trick HTML into doing something it wasn't designed for, let's take a look at the bigger picture and solve it in a conventional manner.