Re: Better Variables through Custom Properties

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 UTC