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

[whatwg] New method for obtaining a CSS property

From: Brett Zamir <brettz9@yahoo.com>
Date: Fri, 28 Jan 2011 14:37:09 +0800
Message-ID: <4D426415.6050901@yahoo.com>
On 1/28/2011 2:22 AM, Boris Zbarsky wrote:
> On 1/27/11 4:48 AM, Brett Zamir wrote:
>> I was thinking of it grabbing the "winning" property for the whole
>> document, i.e., the one which would be applicable without knowing more
>> contextual information. So, if the selector specified were ".error", it
>> wouldn't get "div.error"
>
> That's pretty difficult to define, actually.  Should it get 
> ".error.error"?
>
As mentioned in my other response just now, no, I don't think it should. 
The idea is to be as literal as possible, following a predictable path 
(e.g., the very first or maybe very last reference). It couldn't and 
wouldn't need to follow CSS cascading behavior, since the purpose here 
is different. It would generally be expected that there would only be 
one match since the designer and developer would coordinate to find a 
unique match.

As with regular contextual CSS, one needs to be careful not to overwrite 
one's own rules, but this use case is treating selector-property 
associations as (read-only) variables rather than contextually resolved 
style rules.

Still, it could also be made to follow cascading behavior (e.g., 
!important getting higher precedence). As long as it was predictable, 
the point is for there to be a clear way to figure it out.

>> Whatever the rules, it would be the team's responsibility to ensure it
>> was unique enough to provide the right value (as it is within CSS itself
>> via cascading).
>
> Why is just asking for computed style, and getting correct answers 
> that include the results of the cascade, not the right solution here?
Sure, one could pick an arbitrary element, and hope it didn't have its 
own style attribute, or again, make a pseudo document, but this does not 
seem as satisfying as just querying the stylesheets, as one can do--but 
only by an extra utility function--in iterating through 
document.stylesheets. Best practice should not require hacks, in my 
opinion. One should be able to just tell people, if you want to grab a 
style property value defined in a stylesheet dynamically in JavaScript, 
use this simple method to do so.

thanks,
Brett
Received on Thursday, 27 January 2011 22:37:09 UTC

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