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.
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.
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.
© 2022 - 2024 — McMap. All rights reserved.