Why no :selected?

Or is it proposed and not implemented?

(This is for styling <select> options, to change the appearance of the selected state of the options. option[selected] only changes the option the server set to be selected. Javascript could apply this state to the option onclick to enforce the behavior I guess).

Hi,

I believe the “selected” attribute means pre-selected so it is only available for the initially selected option (via option[selected] {}).

There is no :selected pseudo class as that was changed to :checked:

Only elements that have a ‘user-select’ property other than ‘none’ can have a ::selection. This pseudo-element should not be confused with the :checked pseudo-class (which used to be named :selected)

:checked only applies to radio and check boxes as far as I can see (although the specs mention that it does refer to elements that can have the selected attribute applied - but in practice seems limited to only radio and check boxes though).

The :checked pseudo-class

The :checked pseudo-class only applies to elements which are ‘user-input: enabled’ or ‘user-input : disabled’ (see [UI] for the ‘user-input’ property). Radio and checkbox elements can be toggled by the user. Some menu items are “checked” when the user selects them. When such elements are toggled “on” the :checked pseudo-class applies. The :checked pseudo-class initially applies to such elements that have the HTML4 selected attribute as described in Section 17.2.1 of HTML4, but of course the user can toggle “off” such elements in which case the :checked pseudo-class would no longer apply. While the :checked pseudo-class is dynamic in nature, and is altered by user action, since it can also be based on the presence of the semantic HTML4 selected attribute, it applies to all media.

I found some passing comments here:
http://www.hixie.ch/specs/css/selectors/ProposedChanges.txt
http://lists.w3.org/Archives/Public/www-style/2005Jan/0078.html

To be honest I couldn’t see why there isn’t something in place for option elements but perhaps the multiple selection option confuses the issue.

http://www.whatwg.org/specs/web-apps/current-work/complete/links.html#selector-checked says :checked should matched selected <option>s.

Thanks Simon :slight_smile:

I asume that no UAs have introduced this yet though (at least I couldn’t find any).