:disabled
S2C Home « Selectors « :disabled
UI element states pseudo-class match selector.
Shorthand version $(':disabled')
Description
The :disabled
selector, selects all disabled elements.
- Should only be used for selecting HTML elements that support the disabled attribute, these being (<button>, <input>, <optgroup>, <option>, <select>, <textarea>, and <fieldset>).
- The
:disabled
selector is subtly different from using the Has Attribute Selector via$('[disabled]')
:- The
:disabled
selector matches elements that are actually disabled (WHATWG). - The Has Attribute Selector using
$('[disabled]')
only checks for the existence of the disabled attribute.
- The
Syntax
Signature | Description |
---|---|
jQuery(':disabled') | UI element states pseudo-class match |
Parameters
None.
Return
N/A.
:disabled
ExampleTop
Selects all disabled elements.
The following rather contrived example will check for disabled input elements and set a message in them with a yellow background when the button below is clicked.
$(function(){
$('#btn1').on('click', function() {
$("input:disabled").css('backgroundColor', 'yellow')
.val("this field disabled");
});
});
Please fill in the form: