Is it possible to make an HTML anchor tag not clickable/linkable using CSS?

Viewed 262974

For example if I have this:

<a style="" href="page.html">page link</a>

Is there anything I can use for the style attribute that will make it so the link isn't clickable and won't take me to page.html?

Or, is my only option to simply not wrap 'page link' in an anchor tag?

Edit: I want to state why I want to do this so that people may be able to provide better advice. I am trying to set up my application so that the developer can choose what type of navigation style they want.

So, I have a list of links and one is always currently selected and all the others aren't. For the links that are not selected, I obviously want those to be normal clickable anchor tags. But for the selected link, some people prefer that the link remains clickable while others like to make it not clickable.

Now I could easily just programmatically not wrap an anchor tags around the selected link. But I figure it will be more elegant if I can always wrap the selected link in something like:

<a id="current" href="link.html">link</a>

and then let the developer control the linking style through CSS.

11 Answers

As Simple you do. Put **javascript:void(0)** in href, And see the effect E.g.

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

No Css, No JS Required for this

Questioner specifically asks for CSS solution but according to answers more lines needs to be added just to keep href='page.html'. To me correct approach should be adding onclick HTML attribute. Here is the solution;

<a style="" href="page.html" onclick="this.href=''">page link</a>

This way href link can be kept in coding for future usage.

Related