Skip to content

ally.js

JavaScript library to help modern web applications with accessibility concerns by making accessibility simpler

🔗ally.element.disabled

Makes an element inert, i.e. not editable.

🔗Description

HTML knows the :disabled state for form elements, but lacks something similar for all the other interactive elements. This utility makes a form of this convenient state available to every element.

Elements that were made inert by ally.element.disabled can be identified in the DOM by the attribute [data-ally-disabled="true"] to align with styling of other :disabled elements.

The following things are done in order to make an element inert:

🔗Usage

var element = document.getElementById('victim');
// disable the element
ally.element.disabled(element, true);
// enable the element
ally.element.disabled(element, false);
// check the elements disabled state
var isDisabled = ally.element.disabled(element);

🔗Arguments

NameTypeDefaultDescription
elementHTMLElementrequiredThe Element to modify
stateboolean, undefinedundefinedtrue to disable the element, false

🔗Returns

🔗Throws

TypeError if element argument is not of type HTMLElement.

🔗Examples

🔗Example: ally.element.disabled Example

ally.element.disabled Example on jsbin.com

play with the example on jsbin.com or open the source document

🔗Notes

WARNING: Internet Explorer 10 - 11 leave a few disabled elements focusable and thus editable to the mouse, but not keyboard focusable Trident 962368, Trident 817488 (ally.js does not fix that). One can prevent this wrong behavior by adding :disabled { pointer-events: none; }.
NOTE: In Google Chrome <audio controls> and <video controls> elements are made inert by removing the controls attribute - Blink 512133

🔗Related resources

🔗Contributing