Is there a difference in behaviour or browser support for using the CSS3 selectors :enabled
or not(:disabled)
?
I expect them to be functionally identical, and as they are both CSS3 selectors, browser support should be identical too.
and hash(#) both of them are used as a CSS selector. Both selectors are used to select the content to set the style. CSS selectors select HTML elements according to its id, class, type, attribute, etc. Id selector(“#”): The id selector selects the id attribute of an HTML element to select a specific element.
Simple selectors (select elements based on name, id, class) Combinator selectors (select elements based on a specific relationship between them) Pseudo-class selectors (select elements based on a certain state)
The :enabled pseudo-class in CSS selects focusable elements that are not disabled, and therefore enabled.
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.
Yes, there is a difference — :not(:disabled)
can match elements that are neither :enabled
nor :disabled
. These are elements where enabled/disabled semantics simply don't apply, such as div
, p
, ul
, etc.
The spec confirms this:
What constitutes an enabled state, a disabled state, and a user interface element is language-dependent. In a typical document most elements will be neither
:enabled
nor:disabled
.
Interestingly, the same can't be said for :checked
— there is no corresponding :unchecked
pseudo-class, despite the fact that not all elements have checked/unchecked semantics either. See my answer to this question.
If you're qualifying these pseudo-classes with a type selector (such as input
, select
or textarea
) or a class selector, you probably don't have to worry about this. Still, it makes more sense to use :enabled
than :not(:disabled)
.
Browser support for the majority of level 3 pseudo-classes is indeed identical — there are no known browsers that support either :enabled
or :disabled
only. However, according to MDN it looks like Opera 9.0 and Safari 3.1 don't support :not()
, although they do support :enabled
and :disabled
, and some other features like substring-matching attribute selectors and the general sibling combinator ~
are supported in IE7 with some issues and a little bit better in IE8.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With