RE: [cssom] overwriting an important style

> De : Zack Weinberg [mailto:zackw@panix.com] 
> On Mon, Sep 8, 2014 at 3:32 AM, Simon Pieters <simonp@opera.com> wrote:
> > On Mon, 08 Sep 2014 05:19:12 +0200, Mike Sherov 
> > <mike.sherov@gmail.com>
> > wrote:
> >>
> >> It seems that in order to change from "color: red !important;" to "color:
> >> black;", one should be able to say "elem.style.color = 'black';" or 
> >> at the very least "elem.style.setProperty('color', 'black', '');"
>...
> >
> > https://www.w3.org/Bugs/Public/show_bug.cgi?id=23066
>
> > The idea is that your mental model should be that setProperty('color', 
> > 'black', '') is equivalent to appending a color:black; declaration to 
> > the style rule, which doesn't win over the !important one.
>
> FWIW I still believe quite vehemently that this is wrong, and that setProperty should behave as Sherov expected.  I only dropped the argument (was that a year ago now? sheesh) because I didn't have time to pursue it.

FWIW, me too; I was expecting this issue to come again sooner rather than later, just because the currently specced behavior simply doesn't make sense. I hope someday the CSSWG will be tired of seeing this thread pop out regularly and will just have the guts fixing the issue ^_^

Think of it: if adding a rule is the mental model, then why is the value of the "color" property reset when we add a rule like "color:;" via style.setProperty("color","")? This new declaration should just be ignored. This is not consistent with the explanation you gave previously.

Something that would be, however, is a delete + append combo: delete all declarations for the concerned property and append at the end a new one with the specified value. That would explain the set("...","") behavior in a completely transparent way.

Received on Tuesday, 9 September 2014 08:24:00 UTC