Custom attributes - Yea or nay?

前端 未结 14 2045
南旧
南旧 2020-11-22 03:02

Recently I have been reading more and more about people using custom attributes in their HTML tags, mainly for the purpose of embedding some extra bits of data for use in ja

14条回答
  •  情书的邮戳
    2020-11-22 03:40

    HTML 5 explicitly allows custom attributes that begin with data. So, for example,

    Hello

    is valid. Since it's officially supported by a standard, I think this is the best option for custom attributes. And it doesn't require you to overload other attributes with hacks, so your HTML can stay semantic.

    Source: http://www.w3.org/TR/html5/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes

提交回复
热议问题