W3C home > Mailing lists > Public > www-style@w3.org > April 2011

Re: [css-selectors] Empty input selector

From: Boris Zbarsky <bzbarsky@MIT.EDU>
Date: Wed, 20 Apr 2011 16:30:41 -0400
Message-ID: <4DAF4271.5080505@mit.edu>
To: Rudolph Gottesheim <r.gottesheim@loot.at>
CC: www-style list <www-style@w3.org>
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 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 17:20:39 GMT