23

I select all input elements of a form like this:

var fields = $( form + " :input" ).not( "button" );

How do I check if any of these inputs has the disabled attribute set and remove it when present?

Also, I need to add it after is has been removed (and serialize the fields in between), is there an elegant way for this? Something like toggle but for attributes?

0

4 Answers 4

53

Assuming you are using jQuery 1.6 or above, the suggested method is to use .prop().

fields.prop("disabled", false);

If you need to have logic around each one, you could do something to the extent of

var fields = $( form + " :input" ).not( "button" );
fields.each(function(index, element) {
    var isDisabled = $(element).is(':disabled');
    if (isDisabled) {
        $(element).prop('disabled', false);
    } else {
        // Handle input is not disabled
    }
});

jsfiddle

Sign up to request clarification or add additional context in comments.

Comments

2

You can use the disabled selector

$('input:disabled').attr('disabled', '');

See here

http://jsfiddle.net/JngR9/

Comments

1

use :disabled Selector` try this

$('input:disabled').remove();

Comments

1

To Remove

$('input:disabled').removeProp('disabled');

or

$('input:disabled').prop('disabled', 'disabled');

To Add

$('input:disabled').prop('disabled', 'disabled');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.