开发者

Using non W3C valid attributes on HTML elements

开发者 https://www.devze.com 2022-12-29 00:08 出处:网络
What is your opinion about using non valid attributes on html elements for easier jQuery selectors etc ?

What is your opinion about using non valid attributes on html elements for easier jQuery selectors etc ?

Eg.

<div name="开发者_StackOverflow中文版myDiv"></div>

According to Visual Studio the name attribute is not valid for a div element.


I would recommend using "dummy" classes (and the jQuery class selector) to disambiguate naming of html elements. 100% compliant approach.

Class Selector (“.class”)


If you absolutely must, use the data pseudo-namespace; such as data-id or data-name.

Edit: Using the data pseudo-namespace is far better than perverting the usage of an existing attribute like class or id.


If you still wanted to remain w3c compliant, the w3c allows title attribute for extra information, which you can use in lieu of adding new non-standard attributes.

0

精彩评论

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