What is the easiest way to disable/enable buttons and links (jQuery + Bootstrap)
// Disable — commands to shields up!
$('button, .btn, a').prop('disabled', true).addClass('disabled');
// Enable — Make it so! Engage!
$('button, .btn, a').prop('disabled', false).removeClass('disabled');
These magic words toggle states for buttons and links as effortlessly as changing TV channels.
Build your own jQuery spells
Maybe you need to disable/enable elven elements more often. Here's a custom jQuery spell for that:
Leverage the magic of jQuery's extendability for more fantastic reusable controls.
Dressing up your elements
Give your buttons and links a makeover with CSS selectors [disabled]
or .disabled
:
Pointer-events: none
can protect a princess (element) from unwanted Prince Charming's (user clicks), but beware of the dragon (cross-browser compatibility):
Make your buttons and links guardians to your kingdom:
State | Guardian | Action |
---|---|---|
Enabled | Friendly knight 🛡 | Pass safely |
Disabled | Angry dragon 🐉 | Blocked path |
Commanding your guardians with jQuery + Bootstrap:
Maintain your kingdom's sovereignty from the treacherous hoards (read: website users)!
Mastering interactive guardians
When your kingdom has more knights and dragons than you can count (cough multiple elements cough), ensure harmony:
This way your kingdom stays secure and accessible to your allies.
Avoid excluding magical creatures (a.k.a Accessibility)
Inclusion is key! Ensure to add the disabled
attribute to help magical creatures (users of assistive technologies):
This spell ensures only valid forms can summon the submit button.
Commanding interdimensional portals (Bootstrap modals)
With Bootstrap's modal plugin, control state of buttons within portals (modals) with magic data-*
spells:
Was this article helpful?