# Extend jQuery with enable/disable function

I want to create an extended disable/enable function in jQuery. This is working, but is this the best solution? Is each loop necessary?

 $.fn.ariaDisabled = function (isDisabled) { /// <summary> /// Sets the disabled state. /// </summary> return this.each(function () { var$item = $(this); if (isDisabled === true) {$item
.attr('disabled', 'disabled')
.attr('aria-disabled', 'true')
}
else {
\$item
.removeAttr('disabled')
.removeAttr('aria-disabled')
.removeClass('disabled');
}
});
};

• If the function is called ariaDisabled then it should only change the [aria-disabled] attribute. – zzzzBov Jan 12 '15 at 15:18

• The parameter name is asking a question about the element, not making a statement of what to do. I would rename it to disable which enables the caller to better signify their intent.
• In the same vein, I would also rename the function to ariaDisable as it performs an action as opposed to asking a question