bragboy
bragboy

Reputation: 35542

Is there a better way to do this jQuery functionality

I am trying to bulk disable all the submit buttons present in my form. I am getting all the buttons using the following jQuery

jQuery('input')

This returns me an array of the Input tags. I can iterate through this and disable each and every one of them. But is there a better way to perform this operation. Something like,

jQuery('input').disable()

Upvotes: 2

Views: 83

Answers (4)

James Curran
James Curran

Reputation: 103525

There is no intrinsic disable function. In the book "Jquery In Action", they created enable and disable methods for the example on how to create a jQuery plugin, so I've just kept those and used them.

Upvotes: 0

Tim Down
Tim Down

Reputation: 324597

You can do it efficiently and easily without jQuery:

var inputs = document.body.getElementsByTagName("input");
for (var i = 0, len = inputs.length; i < len; ++i) {
    if (input.type == "submit") {
        inputs[i].disabled = true;
    }
}

Upvotes: 2

Adam
Adam

Reputation: 44939

Use attr it works on collections.

jQuery('input[type=submit]').attr('disabled','disabled');

Upvotes: 2

SLaks
SLaks

Reputation: 887469

Like this:

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

Upvotes: 4

Related Questions