- From: Boris Zbarsky <bzbarsky@MIT.EDU>
- Date: Thu, 16 Feb 2006 12:03:39 -0600
- To: Garrett Smith <dhtmlkitchen@gmail.com>, W3C CSS <www-style@w3.org>
Garrett Smith wrote: > This is about reading a cssRule's selector text specificity. > > http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSStyleRule > > var rule = document.styleSheets[0].cssRules[0]; > > // we get this one for free. > alert(rule.selectorText); // "p.aqua.marine" > > // we can't get this one for free, but we should. > alert(rule.specificity); // "33" (from 0x21). OK. What if rule.selectorText is "p.aqua.marine, div". What should rule.specificity be? "33"? Or "1"? Or "33, 1"? Or an array? > Dean Edwards' CssQuery parses out selector text using RegExp's. This > hard work is already done by the browser in applying rules. It could > easily be exposed so we would have it for free. I agree that this information should be exposed, yeah. I'm just not sure what a decent way to do it is. > The reason this is necessary is for stylesheet editors. A stylesheet > editor should sort the CSS Rules by their specificit so that the end > user can edit the most specific rule to the selected element. That approach really does not work for rules that have multiple selectors and a single declaration, unless your editor splits them up into multiple rules. -Boris
Received on Thursday, 16 February 2006 18:55:38 UTC