John John - 8 months ago 46
CSS Question

CSS: multiple attribute selector

What is the syntax for doing something like

input[name="Sex" AND value="M"]

Basically i just want the input element that has both the attribute name="Sex" and it must have the value="M". Elements like
<input type="radio" name="Sex" value="F" />
should not be selected.


Simple input[name=Sex][value=M] would do pretty nice. ) And it's actually well-described in the standard doc:

Multiple attribute selectors can be used to refer to several attributes of an element, or even several times to the same attribute.

Here, the selector matches all SPAN elements whose "hello" attribute has exactly the value "Cleveland" and whose "goodbye" attribute has exactly the value "Columbus":

span[hello="Cleveland"][goodbye="Columbus"] { color: blue; }

As a sidenote, using quotation marks around an attribute value is required only if this value is not a valid identifier.