8

I have some code that looks like the following coming back from an XHR response:

jQuery(':text:not(:hidden)').removeAttr("disabled");

This is a result of input fields being disabled after form submit. The XHR response returns this tidbit of jQuery and re-enables controls. Works great on every browser, even "partially" on FF 3.6.1 OSX. What I mean by partially is that some text fields have the disabled attribute removed, others do not. These text fields are verified not hidden.

randombits
  • 47,058
  • 76
  • 251
  • 433
  • You should really use jQuery('input:text:not(:hidden)'), it's much quicker according to the jQuery docs. As for your problem, I don't see why it shouldn't work in principle, but right now I don't have FF 3.6.1 to try it. – MartinodF Nov 09 '10 at 21:47
  • For changing the dynamic state, prop() should be used instead of attr()/removeAttr(), see [my answer on disabling buttons](http://stackoverflow.com/a/26035133/664132). – basic6 Jul 08 '15 at 17:25

3 Answers3

15

Have a go using this instead:

jQuery('input:text:visible').each(function(){
    this.disabled = false;
});

This uses the disabled property of the element directly, rather than messing around with jQuery wrappers.

lonesomeday
  • 233,373
  • 50
  • 316
  • 318
  • 1
    Go you. Not that I don't have this problem, but jquery has helped a lot of people forget how to write native javascript. – Jage Nov 09 '10 at 22:11
  • Finally, sanity. jQuery has a lot to answer for, not least the near universal confusion amongst jQuery users about the difference between attributes and properties. – Tim Down Nov 10 '10 at 00:49
  • Had this issue in IE (.removeAttr("disabled"); worked on FF). This 'this.disabled' worked well for both browsers :-) – Dror Sep 16 '11 at 04:08
0

Did you try something like:

jQuery('input[type=text]:visible').removeAttr("disabled");
Bryan A
  • 3,598
  • 1
  • 23
  • 29
-2

Instead try:

jQuery(':text:not(:hidden)').attr("disabled",'');
Daniel
  • 872
  • 1
  • 11
  • 20
  • 2
    It doesn't seem to be the cleanest solution, since in HTML5 the disabled (and other similar) attribute can have any value (even an empty string) and still be valid (``, `` will both be disabled) – MartinodF Nov 09 '10 at 21:51
  • This just ended up disabling all of my text input controls. – randombits Nov 09 '10 at 21:51