Michael Wu
Michael Wu

Reputation: 1267

Disabling elements with Bootstrap

When disabling elements, is there a difference between the following:

<input type="text" disabled>

And:

<input type="text" disabled="disabled">

Specifically, when using jQuery to change the disabled property, will it work as expected for both elements?

Upvotes: 0

Views: 53

Answers (1)

Jimmy Knoot
Jimmy Knoot

Reputation: 2388

Using jQuery to change the disabled property, it will work as expected.

A quote from another answered question: Why do we need disabled="disabled"?

There is an official spec which says you must use that full syntax. But it only applies to xhtml documents. You can find it here (if you search for disabled in that page, you will find that it is listed as only allowing "disabled" as the value. Similarly for the readonly and checked attributes).

Plain HTML - both v4 and v5 - isn't tied to XML's restrictions in this way, and doesn't require an attribute value for disabled; the mere existence of the disabled attribute is sufficient to disable the field, regardless of whether you have a value for the attribute, or what that value is.

The final upshot of all this is that if you are using an XHTML doctype, or you wish to remain XML-compliant, you should use disabled="disabled". If you're not using XHTML and you don't care about having valid XML syntax, then you can just use disabled on its own, or with any attribute value you like.

Upvotes: 2

Related Questions