DEV Community

[Comment from a deleted post]
Collapse
 
millebi profile image
Bill Miller

Nice writeup. Thanks for the links, when I get a chance I'll do some digging.

One question: Why is everyone stuck on multiple classes in CSS? Why not use attributes and make use of the more powerful conditionals available when you assign an attribute to a block? Is it because that's all JQuery supports?

I see so much cruft around parsing and splitting the class list of a block when a simple .setAttribute("blah","yadda") or .removeAttribute("blah") is so much simpler and gives you the cool capabilities of CSS rules like:

div>a[blah~="a b c"] { /* for when blah is one of a, b or c / }
and div>a[blah
="sub"] { /* when blah contains "sub" */ }

... most of which work all the way back into IE8 (I'm using basic "=" comparisons without any trouble. And you can do querySelectorAll("*[blah]") to get all elements with an attribute set to any value anywhere in the DOM)

I find when examining the rendered HTML after the JS has adjusted things to be so much easier to read when reasonably named attributes indicate the state/status of a block.