[whatwg] New method for obtaining a CSS property

Tab Atkins Jr. jackalmage at gmail.com
Wed Jan 26 23:59:10 PST 2011


On Wed, Jan 26, 2011 at 10:23 PM, Brett Zamir <brettz9 at yahoo.com> wrote:
> For example, we want the designer guy to be able to freely change the colors
> in the stylesheet for indicating say a successful transition (green), an
> error (red), or waiting (yellow) for an Ajax request. The JavaScript girl
> does not want to have to change her code every time the designer has a new
> whim about making the error color a darker or lighter red, and the designer
> is afraid of getting balled out for altering her code improperly. So the
> JavaScript girl queries the ".error" class for the "background-color"
> property to get whatever the current error color is and then indicates to an
> animation script that "darkred" should be the final background color of the
> button after the transition. The retrieval might look something like:
>
> document.getCSSPropertyValue(".error", "background-color"); // 'darkred'
>
> While the JavaScript would choose the intermediate RGB steps to get there in
> the fashion desired by the developer.
>
> Yes, there are CSS transitions, or maybe SVG, but this is for cases where
> you want control tied to JavaScript.
>
> Or, for canvas specifically. You draw an animated "Hello" and want the
> designer to be able to choose the fill color. You want to be able to query
> the stylesheet easily to get the styling info.

Given a selector, multiple declaration blocks could match, and within
a single declaration block, multiple copies of the property can match.
 You could get any number of values back from a call like that, and
there's no guarantee that the value you get is worth anything, because
a property from some other declaration block with a different selector
could be winning instead.

It seems that your problem is that you want a way to declare a certain
value to be reused in both CSS and javascript, so that you can change
it in either realm without having to care about it in the other.

This can be solved cleanly and easily with CSS Variables.  The CSS
Working Group has tried several times to agree on how such a thing
should work, so far without success, but Chrome is trying again now.
Check out my blog post on the subject:
<http://www.xanthir.com/blog/b49w0>

~TJ



More information about the whatwg mailing list