pseudo-attributes

Here's an idea for a future level of selectors, which I proposed a
few days ago in
http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2008-October/016544.html


There are some things, like the values of form controls such as text
inputs, that are rather like attributes (in that they have string
values), except they're not actually attributes in the markup.  The
various forms of attribute selectors would all make sense on these
things.

The one I'm suggesting here would be a :value pseudo-attribute,
representing the current value of a text control.  (The value
attribute in HTML represents the default value, not the current
value.)

With this, one could, for example, style inputs that don't have
anything in them:

  input.mandatory[:value=""] { background: red; }

or be used to implement a proposed "placeholder" attribute that
contained text that should be shown until something was entered:

  <input id="search" type="text" placeholder="Search this site">

  input#search[:value=""] {
    content: attr(placeholder); /* assuming 'content' works */;
  }

-David

-- 
L. David Baron                                 http://dbaron.org/
Mozilla Corporation                       http://www.mozilla.com/

Received on Thursday, 16 October 2008 17:37:31 UTC