Skip to content Skip to sidebar Skip to footer

Why Does Disabled = Ture For Html Work?

I noticed in our code that there is a disabled = ture' i the source code for anchor tag. I was wondering why it works in IE. I also searched the internet and it is also being used

Solution 1:

It used to be that to disable an element, you just did <input type="text" disabled>, so most browsers don't really care what goes in that attribute. I believe making it disabled="disabled" became a standard solely so that the code would be valid XML.

Solution 2:

IE only checks for the existence of the disabled property. It's value doesn't matter.

Solution 3:

If you're using a framework like "dojo" to render your GUI widgets the value of this HMTL markup can influence how your components render (and is different for older IE browsers). Dojo pays attention to the value of the DOM object representing the disabled attribute. For example this markup will render an enabled widget providing you are using Chrome or >=IE9:

disabled="false"

This is the opposite of how vanilla HTML components behave which will be disabled purely because the disabled attribute is present (as per Zed's post).

In Chrome and IE9/later the disabled attribute value is accurately persisted into the DOM object that represents it (for example if the attribute is not present in the markup the attribute isn't even defined on the DOM object). Since the DOM object is what drives dojo when it renders its widgets the value in the HTML markup will exert an influence.

In IE8/earlier the attribute's value is persisted into the DOM differently. Firstly the disabled attribute is always present and secondly only its absence ensures the value is false (in which case the dojo widget would appear enabled).

Note: modern IE browsers can be knobbled to regress their behaviour to older versions (such as meta tag X-UA-Compatible with content="IE=8").

Example 1 vanilla html markup

As per Zed's post, only the first of these should be enabled (in any browser):

<button>OK</button><buttondisabled>OK</button><buttondisabled="false">OK</button><buttondisabled="true">OK</button><buttondisabled="mickey">OK</button><buttondisabled="">OK</button>

Example 2 dojo html markup

The first and third of these is enabled with dojo (in Chrome/IE9 or later):

<buttondojoType="dijit.form.Button">OK</button><buttondojoType="dijit.form.Button"disabled>OK</button><buttondojoType="dijit.form.Button"disabled="false">OK</button><buttondojoType="dijit.form.Button"disabled="true">OK</button><buttondojoType="dijit.form.Button"disabled="mickey">OK</button><buttondojoType="dijit.form.Button"disabled="">OK</button>

In IE8 or below the above would render exactly the same as the first example.

Strangely "" evaluates to false value in JavaScript but does not translate into a false value in the context of the above examples (and therefore an enabled widget).

Solution 4:

The disable attribute can take one value: 'disabled'

All instances of this attribute in HTML allow the quotes, separator and name to be omitted (leaving just the unquoted value).

Since browsers implement tag soup parsers and perform vast amounts of error recovery, disabled=pretty much anything will be treated as disabled.

(And I guess that Microsoft have implemented disabled on anchors for some reason, despite the attribute not existing for that element).

Solution 5:

IE is notorious for allowing error-filled HTML code to work; this is why many people mistakenly "blame" it for issues, but actually it's just they've been doing things wrong.

I believe IE allows diabled to be set to anything (other than false) to mean that it's true, because I think in the past people have written disabled='disabled', and other such things.

Post a Comment for "Why Does Disabled = Ture For Html Work?"