0

I'm having issues with attr('disabled', 'disabled') in internet explorer with jQuery 1.7.1. The buttons appear disabled, however if they're clicked they still execute. In firefox, safari, and chrome, this behaves as expected (does nothing, blocking the click). Any ideas?

    disableWizardButtons: function() {
        jQuery(this.wizardButtonSelector).filter(this.enabledSelector).each(function() {
            var button = jQuery(this);
            button.data().originalClass = button.attr('class');
            button.removeClass().addClass('btn-secondary-disabled');
            button.attr('disabled', 'disabled');
            button.prop("onclick", null);
        });
    }
gusterlover6
  • 471
  • 5
  • 10
  • 2
    Did you know that you only have to write `jQuery` in its long form once? By wrapping your code in `(function($) { .... })(jQuery);`, you can use `$` no matter if `noConflict` has been used or not. And you should use `.prop('disabled', true)` to disable an element. Besides that, on a disabled element usually no events are triggered at all. You also shouldn't try to unbind events by clearing the `onclick` property. If you bound them using jQuery, unbind them using `.unbind('click')`. – ThiefMaster Apr 26 '12 at 21:34

2 Answers2

0

Normally you could just use

button.disabled = true;

but since your getting the jQuery obj try

this.disabled = true;
Loktar
  • 34,764
  • 7
  • 90
  • 104
  • 1
    The first code won't work on a jQuery object. But `.prop('disabled', true)` will. But his code should work anyway. Or `this.disabled = true;` – ThiefMaster Apr 26 '12 at 21:36
  • yeah I just added `this` since hes wrapping. I just get frustrated when I see things that are so simple to do in js abstracted by libraries.. – Loktar Apr 26 '12 at 21:37
0

via ThiefMaster:

Did you know that you only have to write jQuery in its long form once? By wrapping your code in (function($) { .... })(jQuery);, you can use $ no matter if noConflict has been used or not. And you should use .prop('disabled', true) to disable an element. Besides that, on a disabled element usually no events are triggered at all. You also shouldn't try to unbind events by clearing the onclick property. If you bound them using jQuery, unbind them using .unbind('click').

gusterlover6
  • 471
  • 5
  • 10