Disable a link in Bootstrap

HtmlCssTwitter BootstrapTwitter Bootstrap-3

Html Problem Overview


The first example didn't work. I need to have always a list to disable links? Or what is wrong with my first demo?

<a class="disabled" href="#">Disabled link</a>

<ul class="nav nav-pills">
  ...
  <li role="presentation" class="disabled"><a href="#">Disabled link</a></li>
  ...
</ul>

https://jsfiddle.net/7y0u2amy/

Html Solutions


Solution 1 - Html

I think you need the btn class.
It would be like this:

<a class="btn disabled" href="#">Disabled link</a>

Solution 2 - Html

It seems that Bootstrap doesn't support disabled links. Instead of trying to add a Bootstrap class, you could add a class by your own and add some styling to it, just like this:

a.disabled {
  /* Make the disabled links grayish*/
  color: gray;
  /* And disable the pointer events */
  pointer-events: none;
}

<!-- Make the disabled links unfocusable as well -->
<a href="#" class="disabled" tabindex="-1">Link to disable</a><br/>
<a href="#">Non-disabled Link</a>

Solution 3 - Html

I just created my own version using CSS. As I need to disabled, then when document is ready use jQuery to make active. So that way a user cannot click on a button until after the document is ready. So i can substitute with AJAX instead. The way I came up with, was to add a class to the anchor tag itself and remove the class when document is ready. Could re-purpose this for your needs.

CSS:

a.disabled{
    pointer-events: none;
    cursor: default;
}

HTML:

<a class="btn btn-info disabled">Link Text</a>

JS:

$(function(){
    $('a.disabled').on('click',function(event){
        event.preventDefault();
    }).removeClass('disabled');
});

Solution 4 - Html

If what you're trying to do is disable an a link, there is no option to do this. I think you can find an answer that will work for you in this question here.

One option here is to use

<a href="/" onclick="return false;">123n</a>

https://stackoverflow.com/questions/13955667/disabled-href-tag

Solution 5 - Html

You cant set links to "disabled" just system elements like input, textfield etc.

But you can disable links with jQuery/JavaScript

$('.disabled').click(function(e){
	e.preventDefault();
});

Just wrap the above code in whatever event you want to disable the links.

Solution 6 - Html

I just removed 'href' attribute from that anchor tag which I want to disable

$('#idOfAnchorTag').removeAttr('href');

$('#idOfAnchorTag').attr('class', $('#idOfAnchorTag').attr('class')+ ' disabled');

Solution 7 - Html

Thanks for @jacob-van-lingen's comment, You can extend .btn-link in your global style

a.disabled{
  @extend .btn-link
}

Solution 8 - Html

I developed the following solution because when I apply class styles such as btn disabled offered by Bootstrap 5 to an <a> element inside a card, margin and padding are applied to the element:

enter image description here

.disabled {
    color: currentColor;
    cursor: not-allowed;
    opacity: 0.5;
    text-decoration: none;
}

<a href="#" class="disabled">Disabled Link</a>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser2990084View Question on Stackoverflow
Solution 1 - HtmlCaampaView Answer on Stackoverflow
Solution 2 - HtmlEmanuela ColtaView Answer on Stackoverflow
Solution 3 - HtmlMikeView Answer on Stackoverflow
Solution 4 - HtmlCassandraView Answer on Stackoverflow
Solution 5 - HtmlHelloWorldView Answer on Stackoverflow
Solution 6 - Htmlasifaftab87View Answer on Stackoverflow
Solution 7 - HtmlfangxingView Answer on Stackoverflow
Solution 8 - HtmlSercanView Answer on Stackoverflow