W3C home > Mailing lists > Public > whatwg@whatwg.org > September 2017

[whatwg] HTML inputs directly toggling CSS classes on elements?

From: Alex Vincent <ajvincent@gmail.com>
Date: Sat, 9 Sep 2017 09:41:34 -0700
Message-ID: <CAEZ8442=mhtYAA6nWXkj6b_N2Boo99ztYnY36TAktKHXOjJxdQ@mail.gmail.com>
To: whatwg@whatwg.org
A few days ago, I dipped my toes into web design again for the first time
in a while.  One of the results is the CSSClassToggleHandler constructor
from [1].  Basically, it takes an radio button or checkbox, and turns that
input into a toggle for a CSS class on another element.

This is relatively easy to do in JavaScript, as the very short function
illustrates. I wonder out of simple curiousity if anyone's considered
defining a short set of attributes to do this in HTML itself, without
requiring JavaScript.

Three attributes on the input would be all that's necessary:

   - cssClassName="(word)" would be the class name to apply
   - cssClassFor="(id)" would be an IDREF to the element which would apply
   the class
   - cssClassNot="true" would invert the class enable/disable (so that if
   the input is checked, the class would be removed instead of applied)

I'm of two minds about this.

On the one hand, if HTML can provide a reference from an input to an
element the input is intended to influence, that has to be useful for
reasons similar to the HTML label element's for attribute, and it makes for
one less dependency on JavaScript.  (Accessibility?)

On the other hand, the modern Web has so much dependency on JavaScript.
Also, the HTML input element has a horrendously long list of attributes on
it already.

So, I thought I'd throw the idea out there and see if anyone likes it.

Alex

[1]
https://github.com/ajvincent/es7-membrane/blob/master/docs/distortions-gui/stylesheet.js#L13-L26

-- 
"The first step in confirming there is a bug in someone else's work is
confirming there are no bugs in your own."
-- Alexander J. Vincent, June 30, 2001
Received on Saturday, 9 September 2017 16:42:04 UTC

This archive was generated by hypermail 2.3.1 : Saturday, 9 September 2017 16:42:05 UTC