Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing data attributes in 'class' vs in HTML5 data-attributes

Can anyone offer an opinion on whether it's better to use the Rails conventions provided in the dom_class and dom_id attributes for semantic helpers like div_for rather than HTML5 data-attributes like 'data-class' or 'data-id'?

ie:

<div id="post_550" class="post">

vs

<div data-class="post" data-id="550">
like image 444
Ben Moss Avatar asked Oct 10 '22 21:10

Ben Moss


1 Answers

Just one opinion...

  • If you're doing css formatting, use div.class.
  • But if you're doing javascript stuff, then I think the html5 attributes make sense.

That way, your presentation stuff is one place, and your data stuff another. You can always mix/match too in your selectors if needed.

like image 72
Jesse Wolgamott Avatar answered Oct 20 '22 06:10

Jesse Wolgamott