How to Toggle Disabled with jQuery

Do you want to toggle the disabled attribute for an input field?

You can use it on checkboxes, radio buttons... well, anything that supports the disabled attribute.

Toggle Disabled Function

(function($) { $.fn.toggleDisabled = function(){ return this.each(function(){ this.disabled = !this.disabled; }); }; })(jQuery);
Code language: JavaScript (javascript)

To use this function you would call it like this:

Code language: JavaScript (javascript)

About Ricard Torres

Senior Front-end Software Engineer at Netcentric, from Barcelona, Haidong Gumdo Instructor (korean martial art of the sword), street photographer, travel lover, TV addict, Boston Red Sox fan, and privacy advocate.

@ricard_dev @ricard_dev

📝 Blog 🎙 Podcast


Leave a Reply

Add <code> Some Code </code> if you need to.