0

I have the following button:

<a type="button" class="btn btn-primary disabledButton">Download</a>

I want to disable it using the .prop property of JQuery. Like this:

$('.disabledButton').prop('disabled', true);

However, it is not working as nothing changed. Any ideas?

kevin_b
  • 803
  • 4
  • 16
  • 34

2 Answers2

2

Has to be a button not an anchor

<button class="btn btn-primary disabledButton">Download</button>

Now this should work

$('.disabledButton').prop('disabled', true);

UPDATED as OP mentioned he has to use an anchor

Workaround one:

$('.disabledButton').css('pointer-events', 'none');

Workaround two: (Prevent default)

 $('.disabledButton').click(function (e) {
    e.preventDefault();
});
Nawwar Elnarsh
  • 1,049
  • 16
  • 28
0

The reason it is not working is because it's a hyper link and it does not have the disabled property. Only thing you can do is preventDefault

https://dev.w3.org/html5/html-author/#the-a-element

<a type="button" class="btn btn-primary disabledButton">Download</a>

$('a.disabledButton').on('click', function(e) {
    e.preventDefault();
});
Robert
  • 10,126
  • 19
  • 78
  • 130