Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
-2
rated 0 times [  1] [ 3]  / answers: 1 / hits: 32236  / 8 Years ago, fri, july 15, 2016, 12:00:00

Hey iv been looking for a solution using JQuery or by modifying the twitter bootstrap class to prevent a button from performing its onclick action aka disabling it. However the results iv found so far have not performed correctly and mostly only give an appearance of being disabled but still perform correctly:



$(#previous).prop('disabled', true);
$(#next).prop('disabled', true);


The purpose is to prevent swapping tabs when the tab index is too high or too low. Most other solutions seem to contain huge amounts of what is seemingly unnecessary Javascript for a feature that seems relatively simple.



Such as this :



$(#previous).click(function() {
var me = $(this);
me.unbind( click);
})


Which is supposed to remove the bound function, however would mean also reattaching the event when the tab index increases. Is there a simpler solution available to temporarily disable a button or just prevent the default action from being carried out without removing the event or not displaying the button element?



Any help would be appreciated :)


More From » jquery

 Answers
111

If you are using twitter bootstrap there is this exactly behavior already implemented for you.



You just need to change the class .disabled of the element you want to disable.



Like:



$(#previous).addClass('disabled');

[#61357] Wednesday, July 13, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cruzs

Total Points: 710
Total Questions: 113
Total Answers: 100

Location: Nepal
Member since Sat, Jul 18, 2020
4 Years ago
cruzs questions
Thu, Nov 26, 20, 00:00, 4 Years ago
Wed, Oct 28, 20, 00:00, 4 Years ago
Wed, Aug 19, 20, 00:00, 4 Years ago
Sun, Aug 2, 20, 00:00, 4 Years ago
;