How to disable a link using only CSS
From this solution:
[aria-current="page"] {
pointer-events: none;
cursor: default;
text-decoration: none;
color: black;
}
<a href="link.html" aria-current="page">Link</a>
Disable Link Using CSS but Enable Title
.disabled-link { pointer-events: none;}
<span datahover="test" title="My Title"><a href="www.google.com" class="disabled-link">My Link</a></span>
How do I disable an a tag link for a certain child of an element?
One option would be to add a click handler. Like this post talks about, you can tell the browser to follow or not to follow the link by calling e.preventDefault()
.
In the code below, change disabled
and you turn on/off the link.
I should add, though, that while I am not an accessibility expert, this is not very "semantic" and I'm guessing probably doesn't work well with screen readers... Maybe something like aria-disabled
could be used to fix that, but I'm not familiar enough with it to say.
var link = document.querySelector('a');var disabled = true;link.addEventListener('click', (e) => { if (disabled) { console.log('disabled'); e.preventDefault(); }});
<a href="https://google.com">My link</a>
Disable link in dropdown menu but keep the css
Try this :
<a href='#'>Bewerkingen</a>
You will not need to use
a[href="/test4/disabled"] {
pointer-events: none;
}
Disabled href tag
There is no disabled attribute for hyperlinks. If you don't want something to be linked then you'll need to remove the <a>
tag altogether.
Alternatively you can remove its href
attribute - though this has other UX and Accessibility issues as noted in the comments below so is not recommended.
Disable html anchor in Internet Explorer
You can use pointer-events css property to disable the links but they have known issues with ie. Starting from ie 11 this property is supported. There is a little hack. You should add disabled class to links and add disabled attribute to the link then add css that is given below. Also you need to provide pointer-events none for disabled anchor attribute. After these two this should work in most browsers.
a.disabled {
pointer-events: none;
}
a[disabled] {
pointer-events: none;
}
See this fiddle.
Related Topics
How to Hide Link Information At the Bottom Left/Right of the Browser on Hover
How to Put Arrow Between Two Divs Using HTML and CSS
Background Size for Mobile Devices
How to Customize the Validation of Input Type File Image
Where Is the Extra Space Coming from Around This Textarea
How to Make the Height of the Div Dynamically Fit the Size of the Div in Which It Is Contained
How to Make Custom Dots in Owl Carousel
Multiple Select Dropdown Not Working With Ng-Option
How to Make Vertical Lines Between List Items Using CSS
Inserting Form Data into MySQL Database When Using Nodejs Express
How to Remove Unwanted Space in This Table
How to Create a Link to a Local File on a Locally-Run Web Page
How to Set Max-Length in an Html5 "Input Type=Number" Element
How to Add Some Non-Standard Font to a Website
Binding Select Element to Object in Angular
Is a Url Allowed to Contain a Space
Why Position:Sticky Is Not Working When the Element Is Wrapped Inside Another One
How to Disable Browser Autocomplete on Web Form Field/Input Tags