I have created custom styled buttons in my page and would like to toggle their class and therefore their look when they get disabled or enabled. So is there any way to call a function when .removeAttr ('disabled'), .attr('disabled', ''), and .attr('disabled', 'disabled') are invoked? Basically, is there any way to have enable/disable act like an event such as click, mouseover, etc.?
I've tried overwriting the jQuery function as follows: jQuery.fn.removeAttr = function(name) { if(this.eq(0).hasClass('buttonDisabled') && name == 'disabled') this.eq(0).removeClass('buttonDisabled'); jQuery.attr(this.get(0), name, "" ); if (this.get(0).nodeType == 1) this.get(0).removeAttribute(name); }; and when $('.buttonDisabled').removeAttr('disabled') is called, the disabled attribute and buttonDisabled class are removed. This is what I want, but it doesn't seem right. I shouldn't be overwriting the removeAttr function. Also, I'd have to do the same thing for jQuery's attr() function to add the buttonDisabled class when .attr('disabled', 'disabled') is called. Can I add the code I need to the functions and then call "super" somehow? Is there a simpler way to achieve what I want?