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
  • 741
  • 3
  • 14
  • 33

2 Answers2

1

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
  • 977
  • 15
  • 27
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 Rocha
  • 9,510
  • 18
  • 69
  • 121