5

Does

$('#myElem').attr('disabled',true);

on a disabled element trigger any event listener associated to it? (change(),click() or whatever)

Whimusical
  • 6,401
  • 11
  • 62
  • 105
  • 2
    Why should it? You merely change an attribute / property of the HTML/DOM element. This never triggers any event. – Felix Kling Aug 15 '12 at 13:15
  • Dunno.. You are implicitly changing values from non-existant null to default selection – Whimusical Aug 15 '12 at 13:16
  • This may help you http://stackoverflow.com/questions/4561845/firing-event-on-dom-attribute-change – Adil Aug 15 '12 at 13:17
  • Why do you think it changes values to default values? I have never heard of that and quick test does not show such behaviour: http://jsfiddle.net/vQpsG/ – Felix Kling Aug 15 '12 at 13:19
  • `true` only makes sense with `.prop`, if you changed this to `false` you would get unexpected results. Edit: it looks like jQuery uses properties for this so never mind. – Esailija Aug 15 '12 at 13:26
  • It changes values to default vlaues in some cases. For example selects, the value is not send in a post if disabled, but once enabled again it contains the previous value. For the second question: prop only work for jQuery >= 1.6. ('disabled',true) works for my using jquery 1.5 – Whimusical Aug 15 '12 at 13:32
  • Disabled form elements are *never* sent to the server. That's how it is defined. As far switching back to the default value after it was enabled again, it does not happen for me: http://jsfiddle.net/vQpsG/1/. If you really experienced this, then I would be interested in seeing a http://jsfiddle.net/ which demonstrates this. – Felix Kling Aug 15 '12 at 14:28
  • http://jsfiddle.net/xSGLF/1/ You can see how enabling returns select to previous state, and so, it is making an implicit change from null value to previous select. Maybe we are saying the same but with different words – Whimusical Aug 15 '12 at 14:41

2 Answers2

6

No.

http://jsfiddle.net/5sbpq/1/

BenM
  • 52,573
  • 26
  • 113
  • 168
  • I did not want to test absolutely all events, but I guess these two are the most significative. Or maybe the only ones if you just tested these – Whimusical Aug 15 '12 at 13:35
4

Here is what disabled does http://www.w3.org/TR/html401/interact/forms.html#h-17.12.1

17.12.1 Disabled controls

Attribute definitions

disabled [CI] When set for a form control, this boolean attribute disables the control for user input. When set, the disabled attribute has the following effects on an element:

Disabled controls do not receive focus. Disabled controls are skipped in tabbing navigation. Disabled controls cannot be successful. The following elements support the disabled attribute: BUTTON, INPUT, OPTGROUP, OPTION, SELECT, and TEXTAREA.

This attribute is inherited but local declarations override the inherited value.

How disabled elements are rendered depends on the user agent. For example, some user agents "gray out" disabled menu items, button labels, etc.

It will not trigger any events. It's more of a functionality thing where it will not allow a user interact with an element nor will it send the value of the field on submit if it's inside a form.

wirey00
  • 33,517
  • 7
  • 54
  • 65