|
|
|
|
|
by jonahx
3888 days ago
|
|
If you're saying your sole reason for doing this is to ease your javascript selection, I think that's a poor reason. If you have a serious dynamic javascript page of any complexity, you have should have a pure js model and your view should be updating off that, using react, mithril, or your own vanilla update function. Now, not everyone would agree with that, and there may be use cases where it's overkill, but in that case I still don't buy the argument, as you can just write a short helper function that makes things just as easy as selecting with dataset. I don't think a fear of javascript should be driving decisions about markup. You should write your markup in the clearest, most semantic way possible, and let what are ultimately trivial js problems take care of themselves. |
|
Semantically is exactly why data-* should be used instead of classes. But semantics often include a bit of extra work (adding a data-filter attribute instead of just throwing an extra class in the mix) and so people throw them aside all too often.
>I still don't buy the argument, as you can just write a short helper function that makes things just as easy as selecting with dataset.
So to avoid doing things the proper way you would write a helper function to get around a problem?
The CSS can be written both ways (you can use [data-filter="..."] as a selector). The difference is between using data-* or adding a class. The difference between the two comes down to semantics and in some niche scenarios the ability to easily change the value.