you can't do this because pointer-events: none; disable all mouse functions, but you can do a trick and wrap your button with a div then use cursor: not-allowed; on this. Work great.
Apply the CSS property cursor:pointer; to the elements. (This is the default style when a cursor hovers over a button.) Apply the CSS property cursor:url(pointer. png); using a custom graphic for your pointer.
Using pointer-events: none
will disable all mouse interactions with that element. If you wanted to change the cursor
property, you would have to apply the changes to the parent element. You could wrap the link with an element and add the cursor
property to it.
Example Here
HTML
<span class="wrapper">
<a href="#">Some Link</a>
</span>
CSS
.wrapper {
position: relative;
cursor: text; /* This is used */
}
.wrapper a {
pointer-events: none;
}
There are a few browser inconsistencies, though. To make this work in IE11, it seems like you need a pseudo element. The pseudo element also allows you to select the text in FF. Oddly enough, you can select the text in Chrome without it.
Updated Example
.wrapper:after {
content: '';
position: absolute;
width: 100%; height: 100%;
top: 0; left: 0;
}
It's pretty long since original question, but this is my solution without any wrapping element and cursor with no pointer-events:
<!-- Add tabindex="-1" so that element cannot be reached by keyboard -->
<a href="url" aria-disabled="true" tabindex="-1" onfocus="blur()">Disabled link</a>
CSS:
/* Adding cursor just works: */
a[aria-disabled="true"] {
cursor: not-allowed;
}
/* Makes link non-clickable: */
a[aria-disabled="true"]:active {
pointer-events: none;
}
CodePen Example
EDIT:
onfocus="blur()"
to unfocus element.EDIT 2
class="disabled"
with aria-disabled="true"
to meet the a11y ;)By specifying pointer-events:none
you are actively declaring that there is no mouse interaction between the element and the cursor. Therefore it cannot have a cursor either - it's invisible to all mouse behaviours.
Proof to be found here.
Remove pointer-events: none !important;
. Disable the link using JavaScript:
anchorElement.onclick = function(){
return false;
}
If you don't know JavaScript anchorElement
is the Node or Element itself. The most common way to get an Element is by using the HTML id
attribute. Let's say we have:
<a id='whatever' href='#'>Text Here</a>
You code could be:
document.getElementById('whatever').onclick = function(){
return false;
}
There are a number other ways to get Nodes.
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