Html element disabled property

:disabled

The :disabled CSS pseudo-class represents any disabled element. An element is disabled if it can’t be activated (selected, clicked on, typed into, etc.) or accept focus. The element also has an enabled state, in which it can be activated or accept focus.

Try it

Syntax

Examples

This example shows a basic shipping form. It uses the JavaScript change event to let the user enable/disable the billing fields.

HTML

form action="#"> fieldset id="shipping"> legend>Shipping addresslegend> input type="text" placeholder="Name" /> input type="text" placeholder="Address" /> input type="text" placeholder="Zip Code" /> fieldset> br /> fieldset id="billing"> legend>Billing addresslegend> label for="billing-checkbox">Same as shipping address:label> input type="checkbox" id="billing-checkbox" checked /> br /> input type="text" placeholder="Name" disabled /> input type="text" placeholder="Address" disabled /> input type="text" placeholder="Zip Code" disabled /> fieldset> form> 

CSS

input[type="text"]:disabled  background: #ccc; > 

JavaScript

// Wait for the page to finish loading document.addEventListener( "DOMContentLoaded", () =>  // Attach `change` event listener to checkbox document.getElementById("billing-checkbox").onchange = toggleBilling; >, false, ); function toggleBilling()  // Select the billing text fields const billingItems = document.querySelectorAll('#billing input[type="text"]'); // Toggle the billing text fields billingItems.forEach((item) =>  item.disabled = !item.disabled; >); > 

Result

Specifications

Browser compatibility

BCD tables only load in the browser

Источник

HTML attribute: disabled

The Boolean disabled attribute, when present, makes the element not mutable, focusable, or even submitted with the form. The user can neither edit nor focus on the control, nor its form control descendants.

Try it

Overview

If the disabled attribute is specified on a form control, the element and its form control descendants do not participate in constraint validation. Often browsers grey out such controls and it won’t receive any browsing events, like mouse clicks or focus-related ones.

The disabled attribute is supported by , , , , , and .

This Boolean disabled attribute indicates that the user cannot interact with the control or its descendant controls. If this attribute is not specified, the control inherits its setting from the containing element, for example fieldset ; if there is no containing element with the disabled attribute set, and the control itself does not have the attribute, then the control is enabled. If declared on an , the select is still interactive (unless otherwise disabled), but none of the items in the option group are selectable.

When a supporting element has the disabled attribute applied, the :disabled pseudo-class also applies to it. Conversely, elements that support the disabled attribute but don’t have the attribute set match the :enabled pseudo-class.

This Boolean attribute prevents the user from interacting with the button. If this attribute isn’t set, the button can still be disabled from a containing element, for example ; if there is no containing element with the disabled attribute set, then the button is enabled.

Firefox will, unlike other browsers, persist the dynamic disabled state of a across page loads. Use the autocomplete attribute to control this feature.

Attribute interactions

The difference between disabled and readonly is that read-only controls can still function and are still focusable, whereas disabled controls can not receive focus and are not submitted with the form and generally do not function as controls until they are enabled.

Because a disabled field cannot have its value changed, required does not have any effect on inputs with the disabled attribute also specified. Additionally, since the elements become immutable, most other attributes, such as pattern , have no effect, until the control is enabled.

Note: The required attribute is not permitted on inputs with the disabled attribute specified.

Usability

Browsers display disabled form controls greyed as disabled form controls are immutable, won’t receive focus or any browsing events, like mouse clicks or focus-related ones, and aren’t submitted with the form.

If present on a supporting elements, the :disabled pseudo class will match. If the attribute is not included, the :enabled pseudo class will match. If the element doesn’t support the disabled attribute, the attribute will have no effect, including not leading to being matched by the :disabled and :enabled pseudo classes.

Constraint validation

If the element is disabled , then the element’s value can not receive focus and cannot be updated by the user, and does not participate in constraint validation.

Examples

fieldset> legend>Checkboxeslegend> p> label> input type="checkbox" name="chbox" value="regular" /> Regular label> p> p> label> input type="checkbox" name="chbox" value="disabled" disabled /> disabled label> p> fieldset> fieldset> legend>Radio buttonslegend> p> label> input type="radio" name="radio" value="regular" /> Regular label> p> p> label> input type="radio" name="radio" value="disabled" disabled /> disabled label> p> fieldset> p> label >Select an option: select> optgroup label="Group 1"> option>Option 1.1option> optgroup> optgroup label="Group 2"> option>Option 2.1option> option disabled>Option 2.2option> option>Option 2.3option> optgroup> optgroup label="Group 3" disabled> option>Disabled 3.1option> option>Disabled 3.2option> option>Disabled 3.3option> optgroup> select> label> p> fieldset disabled> legend>Disabled fieldsetlegend> p> label> Name: input type="name" name="radio" value="regular" /> Regular label> p> p> label>Number: input type="number" />label> p> fieldset> 

Specifications

Browser compatibility

html.elements.button.disabled

BCD tables only load in the browser

html.elements.fieldset.disabled

BCD tables only load in the browser

html.elements.input.disabled

BCD tables only load in the browser

html.elements.optgroup.disabled

BCD tables only load in the browser

html.elements.option.disabled

BCD tables only load in the browser

html.elements.select.disabled

BCD tables only load in the browser

html.elements.textarea.disabled

BCD tables only load in the browser

See also

Found a content problem with this page?

This page was last modified on May 22, 2023 by MDN contributors.

Your blueprint for a better internet.

MDN

Support

Our communities

Developers

Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998– 2023 by individual mozilla.org contributors. Content available under a Creative Commons license.

Источник

HTMLInputElement: disabled property

The HTMLInputElement.disabled property is a boolean value that reflects the disabled HTML attribute, which indicates whether the control is disabled. If it is disabled, it does not accept clicks. A disabled element is unusable and un-clickable.

Value

Examples

HTML

p> label> input id="check-box" name="b" value="1" type="checkbox" disabled /> Check this box! label> p> p> label> input id="toggle-box" name="b" value="2" type="checkbox" /> Enable the other checkbox. label> p> 

JavaScript

const checkBox = document.getElementById("check-box"); const toggleBox = document.getElementById("toggle-box"); toggleBox.addEventListener( "change", (event) =>  checkBox.disabled = !event.target.checked; >, false, ); 

Result

Specifications

Browser compatibility

BCD tables only load in the browser

Found a content problem with this page?

This page was last modified on Jul 7, 2023 by MDN contributors.

Your blueprint for a better internet.

MDN

Support

Our communities

Developers

Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998– 2023 by individual mozilla.org contributors. Content available under a Creative Commons license.

Источник

HTMLSelectElement: disabled property

The HTMLSelectElement.disabled property is a boolean value that reflects the disabled HTML attribute, which indicates whether the control is disabled. If it is disabled, it does not accept clicks. A disabled element is unusable and un-clickable.

Value

Examples

HTML

label> Allow drinks? input id="allow-drinks" type="checkbox" /> label> label for="drink-select">Drink selection:label> select id="drink-select" disabled> option value="1">Wateroption> option value="2">Beeroption> option value="3">Pepsioption> option value="4">Whiskyoption> select> 

JavaScript

const allowDrinksCheckbox = document.getElementById("allow-drinks"); const drinkSelect = document.getElementById("drink-select"); allowDrinksCheckbox.addEventListener( "change", (event) =>  drinkSelect.disabled = !event.target.checked; >, false, ); 

Result

Specifications

Browser compatibility

BCD tables only load in the browser

Found a content problem with this page?

This page was last modified on Jul 7, 2023 by MDN contributors.

Your blueprint for a better internet.

MDN

Support

Our communities

Developers

Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998– 2023 by individual mozilla.org contributors. Content available under a Creative Commons license.

Источник

HTMLStyleElement: disabled property

The HTMLStyleElement.disabled property can be used to get and set whether the stylesheet is disabled ( true ) or not ( false ).

Note that there is no corresponding disabled attribute on the HTML element.

Value

Returns true if the stylesheet is disabled, or there is no associated stylesheet; otherwise false . The value is false by default (if there is an associated stylesheet).

The property can be used to enable or disable an associated stylesheet. Setting the property to true when there is no associated stylesheet has no effect.

Examples

Disabling an inline style

This example demonstrates programmatically setting the disabled property on a style that was defined in the HTML using the HTML element. Note that you can also access any/all stylesheets in the document using Document.styleSheets .

HTML

button>Enablebutton> style id="InlineStyle"> p  color: blue; > style> p>Text is black when style is disabled; blue when enabled.p> p>p> 

JavaScript

The code below gets the style element using its id, and then sets it as disabled. As the style already exists, as it is defined in the SVG, this should succeed.

const style = document.getElementById("InlineStyle"); style.disabled = true; 

We then add an event handler for the button that toggles the disabled value and button text.

const button = document.querySelector("button"); button.addEventListener("click", () =>  style.disabled = !style.disabled; const buttonText = style.disabled ? "Enable" : "Disable"; button.innerText = buttonText; >); 

Result

The result is shown below. Press the button to toggle the disabled property value on the style used for the paragraph text.

Disabling a programmatically defined style

This example is very similar to the one above, except that the style is defined programmatically.

HTML

The HTML is similar to the previous case, but the definition does not include any default styling.

button>Enablebutton> p>Text is black when style is disabled; blue when enabled.p> p>p> 

JavaScript

First we create the new style element on the HTML. This is done by first creating a style element using Document.createElement() , creating and appending a text node with the style definition, and then appending the style element to the document body.

// Create the `style` element const style = document.createElement("style"); const node = document.createTextNode("p < color: blue; >"); style.appendChild(node); document.body.appendChild(style); 

We can then disable the style as shown below. Note that this is the earliest point at which setting the property to true will succeed. Before this point the document did not have an associated style, and so the value defaults to false .

//Disable the style style.disabled = true; 

Last of all we add an event handler for the button that toggles the disabled state and button text (this is the same as in the previous example).

const button = document.querySelector("button"); button.addEventListener("click", () =>  style.disabled = !style.disabled; const buttonText = style.disabled ? "Enable" : "Disable"; button.innerText = buttonText; >); 

Result

The result is shown below. Press the button to toggle the disabled state on the style used for the text.

Specifications

Browser compatibility

BCD tables only load in the browser

See also

Found a content problem with this page?

This page was last modified on Apr 7, 2023 by MDN contributors.

Your blueprint for a better internet.

MDN

Support

Our communities

Developers

Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998– 2023 by individual mozilla.org contributors. Content available under a Creative Commons license.

Источник

Читайте также:  Find java version in browser
Оцените статью