Re: XHTML 2.0 considered harmful

Boris Zbarsky wrote:

>Sure there is and a major one.  Compare the following two chunks of ECMAScript:
>
>  document.getElementById("myMovableDiv").style.left = "50px";
>
>and
>
>  var set = false;
>  var rules = document.styleSheets[0].cssRules;
>  var len = rules.length;
>  while (var i = 0; i < len; ++i) {
>    var rule = rules[i];
>    if (rule.selectorText == "#myMovableDiv") {
>      rule.style.left = "50px";
>      set = true;
>      break;
>  }
>  if (!set) {
>    document.styleSheets[0].insertRule("#myMovableDiv { left: 50px }", rules.length);
>  }
>
>  
>

This code is not even complete, Boris...

Why do you pre-suppose there is only one stylesheet in the document ? 
Why do you pre-suppose document.styleSheets[0] corresponds to a 
stylesheet that the tool is able to save ? Why do you pre-suppose the 
rule you are looking for is directly a child of the sheet and not itself 
contained in an at-media rule for instance ? And so on...

The only way to simplify that would be the availability of a DOM method 
taking two arguments : (a) an element (b) a CSS property name, and 
returning the CSS rule responsible for the computed value of the 
property for that element. In other terms, a reverse cascade.

Without that, dealing with style rules to set one individual property is 
a nightmare compared to the style attribute.

</Daniel>

Received on Thursday, 16 January 2003 04:26:08 UTC