W3C home > Mailing lists > Public > www-style@w3.org > October 2011

Re: Better Variables through Custom Properties

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Tue, 25 Oct 2011 12:51:57 -0700
Message-ID: <CAAWBYDAdC=0+eYpMGopAKL1u6voyZ9uc966=2F3gfeDbq5vmhA@mail.gmail.com>
To: Brian Kardell <bkardell@gmail.com>
Cc: Roland Steiner <rolandsteiner@google.com>, Boris Zbarsky <bzbarsky@mit.edu>, www-style@w3.org
On Tue, Oct 25, 2011 at 10:41 AM, Brian Kardell <bkardell@gmail.com> wrote:
> I take it from Tab's "similar to the data-* attributes in HTML" that
> these are not HTML data attributes and would not be exposed in a
> writable way via DOM/script?

This is completely separate from HTML's data-* attributes.  They
simply have similar uses, and purposely use the same name to make them
easier to understand.

The CSS variables are certainly exposed in a writable way via script:

el.style.dataFoo = "bar";
// Now the data-foo property on el is set to the keyword 'bar'


On Tue, Oct 25, 2011 at 11:07 AM, Brian Kardell <bkardell@gmail.com> wrote:
> What if you had
>
> #x {
>    data-foo: attr(data-foo);
> }
>
> and then in script you change the value of the attribute 'data-foo'?

It would do exactly what any other property and attribute would do.
The CSS property named data-foo would be set to the (string) value of
the HTML attribute named data-foo.  If the HTML attribute changes, the
CSS property changes as well, exactly like any other property and
attribute would do.

~TJ
Received on Tuesday, 25 October 2011 19:52:45 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 17:20:45 GMT