Joe Van Dyk
Joe Van Dyk

Reputation: 6940

Is it a good idea to use html5 data attributes for javascript selectors?

I'm trying to make it really obvious in the DOM that javascript code depends on the structure. Is the following a good idea?

HTML:
<a class='submenu' data-submenu="true" .... </a>

JS:
var mySubnav = $("[data-submenu]");

Makes it really clear that javascript is operating on the html. But I haven't seen this used by other people.

Upvotes: 0

Views: 131

Answers (1)

n0wak
n0wak

Reputation: 76

I'm not sure why you can't just use classes for this case? If your links have a subnav class that's far more compatible and easy to parse, plus stylable, than a data-submenu attribute.

Upvotes: 1

Related Questions