开发者

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 开发者_JAVA百科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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜