W3C home > Mailing lists > Public > whatwg@whatwg.org > January 2011

[whatwg] New method for obtaining a CSS property

From: Boris Zbarsky <bzbarsky@MIT.EDU>
Date: Thu, 27 Jan 2011 13:19:52 -0500
Message-ID: <4D41B748.2060502@mit.edu>
On 1/27/11 1:23 AM, Brett Zamir wrote:
> I'll give a more concrete example, but I did state the problem:
> separation of concerns, and the data I want, getting a CSS property for
> a given selector.

"selectors" don't have properties.   Elements have properties, and 
declarations have properties.  "selectors" are a mechanism for tying 
rulesets to declarations.

> 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'

You can do that right now using getComputedStyle, with a bit more code, 

> 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.

Or just set a class on your canvas and let styles apply to it as normal?

Received on Thursday, 27 January 2011 10:19:52 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:30 UTC