开发者

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

开发者 https://www.devze.com 2023-03-31 05:35 出处:网络
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?

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

精彩评论

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