Re: [css-selectors] Empty input selector

On 4/20/11 4:00 PM, Rudolph Gottesheim wrote:
> input[value=''] { background-color:#f00; }

This is selecting on the value returned by getAttribute('value')

> Why doesn't the second input turn red when you enter something?

Because when you type in the input it doesn't change the value of the 
'value' attribute.  You can test this by examining what 
getAttribute('value') returns.

> Why isn't there a pseudo class selector for form fields with an empty value?

Do you really want to select form fields with an empty value, or invalid 
required form fields?  There's certainly a selector for the latter!

> One use case would be to remove the border from all input fields that
> have a value so they look just like normal text and to add it back on
> :hover and :focus.

You can more or less do this in Gecko with :-moz-placeholder, for what 
it's worth.

-Boris

Received on Wednesday, 20 April 2011 20:31:11 UTC