Hacker News new | ask | show | jobs
by Nadya 3888 days ago
>You should write your markup in the clearest, most semantic way possible

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.

1 comments

All I'm saying is that so far the only tangible reason you've given is that it makes doing javascript selections easier. I'm not saying using data-* liberally is a bad idea, I'm saying that is a bad reason for it. You've also mentioned semantics, which would be a good reason, but I'm still unlcear what the semantic argument is. To use the stripe row example, 'class="alternateRow"' seems just as semantic as 'data-rowtype="alternate"'. If I'm still missing something, I'd like to learn more. Again, additional examples would help. Discussing this kind of thing in the abstract is a recipe for miscommunication.