Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
178
rated 0 times [  182] [ 4]  / answers: 1 / hits: 21454  / 8 Years ago, tue, january 17, 2017, 12:00:00

I have a number of links (A elements) STYLED AS buttons with class btn and when one of them is clicked, I want that particular button to be disabled. this code doesn't work:



$('.btn').on('click', function(e) {
$(this).prop('disabled',true);
});


There are a gazillion tutorials for preventing the default event of a form submit button, and then disabling that, but that is not quite what I need...



Apparently, my $this isn't pointing to the correct object, or something =)



----------- UPDATE ---------------



SORRY, update above. The element I have is not a button, it is a link styled as a button...


More From » jquery

 Answers
10

Don't try to disable the Anchor tag. Try to set the href instead.



$('.btn').on('click', function(e) {
e.preventDefault();
$(this).off(click).attr('href', javascript: void(0););
//add .off() if you don't want to trigger any event associated with this link
});

[#59332] Friday, January 13, 2017, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
pierre

Total Points: 716
Total Questions: 128
Total Answers: 102

Location: Djibouti
Member since Sun, Feb 27, 2022
2 Years ago
;