I would like to explicitly set a button as enabled in the html file. The reason is that my code later on toggles the button to disabled and if the code crashes or so I might see the button disabled.
I can disable the button with
$("#btn").attr("disabled","true")
but then an html containing:
<button id="btn" disabled="false">I want to be enabled!</button>
still shows the button as disabled. The inspector shows:
<button id="btn" disabled="">I want to be enabled!</button>
I know I can do
$("#btn").removeAttr("disabled")
or similar, but it is not convenient to do that for many elements in the html.
HTML doesn't use boolean values for boolean attributes, surprisingly.
In HTML, boolean attributes are specified by either merely adding the attribute name, or (especially in XHTML) by using the attribute name as its value.
<input type="checkbox" disabled> <!-- HTML -->
<input type="checkbox" disabled /> <!-- Also HTML -->
<input type="checkbox" disabled="disabled" /> <!-- XHTML and HTML -->
This is documented in the HTML specification: http://www.w3.org/TR/html5/infrastructure.html#boolean-attribute
A number of attributes are boolean attributes. The presence of a boolean attribute on an element represents the true value, and the absence of the attribute represents the false value.
The values "true" and "false" are not allowed on boolean attributes. To represent a false value, the attribute has to be omitted altogether.