0

What's the real and working way to make a twitter bootstrap button (which is a LINK) disabled? They mostly suggest that it is:

$("#my_btn").prop("disabled", true); //1
//or
$("#my_btn").attr("disabled", true); //2

But this does NOT work. What does work?

Angel S. Moreno
  • 2,441
  • 3
  • 24
  • 36
アレックス
  • 24,309
  • 37
  • 129
  • 229

3 Answers3

3

A link doesn't actually have a disabled attribute.

Instead, you'll need to add the .disabled css class.

$("#my_btn").addClass("disabled");

http://getbootstrap.com/css/#buttons-disabled (The section on Anchor element)

As per the discussion below, you should note that this isn't a sure-fire way of actually disabling the link in all browsers. It only uses CSS's pointer-events: none, which isn't as robust as the disabled attribute on a <button> element.

doctororange
  • 10,902
  • 11
  • 40
  • 57
1

What version of jQuery you using? If you need disable a link, you can add a CSS class .disabled to that link with this jQuery command:

$("#my_btn").addClass("disabled");

This code below is working for INPUT only

jQuery 1.6+

$("input").prop('disabled', true);
$("input").prop('disabled', false);

jQuery 1.5 and below

$("input").attr('disabled','disabled');
$("input").removeAttr('disabled');

In any version of jQuery

// assuming an event handler thus 'this'
this.disabled = true;

You can check this thread: Disable/enable an input with jQuery? and here you will find your answer I hope :)

Community
  • 1
  • 1
pes502
  • 1,574
  • 3
  • 17
  • 30
0

It's quite simple!

just add the disabled class. Disabled:

<button class="btn btn-default disabled">Text</button>

Non disabled:

  <button class="btn btn-default">Text</button>
Despertaweb
  • 1,253
  • 15
  • 27