In order to disable a HTML Anchor Link (HyperLink), the value of its HREF attribute is copied to the REL attribute and the value of HREF attribute is set to an empty JavaScript function. This makes the HTML Anchor Link (HyperLink) disabled i.e. non-clickable.
Answer: Use the CSS pointer-events Property You can simply use the CSS pointer-events property to disable a link. The none value of this property specify the element is never the target of pointer events.
CSS Code. When styling the text of the link itself, we simply reference the anchor tag class name only, and we change change things such as the text's color and other attributes. When referencing the special attributes of the anchor tag, such as link, visited, hover, and active.
You can use this css:
.inactiveLink {
pointer-events: none;
cursor: default;
}
And then assign the class to your html code:
<a style="" href="page.html" class="inactiveLink">page link</a>
It makes the link not clickeable and the cursor style an arrow, not a hand as the links have.
or use this style in the html:
<a style="pointer-events: none; cursor: default;" href="page.html">page link</a>
but I suggest the first approach.
That isn't too easy to do with CSS, as it's not a behavioral language (ie JavaScript), the only easy way would be to use a JavaScript OnClick Event on your anchor and to return it as false, this is probably the shortest code you could use for that:
<a href="page.html" onclick="return false">page link</a>
Yes.. It is possible using css
<a class="disable-me" href="page.html">page link</a>
.disable-me {
pointer-events: none;
}
Or purely HTML and CSS with no events:
<div style="z-index: 1; position: absolute;">
<a style="visibility: hidden;">Page link</a>
</div>
<a href="page.html">Page link</a>
CSS was designed to affect presentation, not behaviour.
You could use some JavaScript.
document.links[0].onclick = function(event) {
event.preventDefault();
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With