Does using custom data attributes produce browser compatibility issues?

前端 未结 2 934
旧时难觅i
旧时难觅i 2021-02-20 14:33

I have to choose between custom data tags or ids. I would like to choose custom data tags, but I want to be sure that they do not cause browser compatibility issues for the most

相关标签:
2条回答
  • 2021-02-20 15:01

    this guy says data attibutes work on IE6.

    0 讨论(0)
  • 2021-02-20 15:09

    I would advise in favor of data attributes for the following reasons:

    • ids need to be unique document-wide. Thus they are limited in the semantics they can carry
    • you can have multiple data-attributes per element

    and probably less relevant in your case:

    • changing ids might break idrefs

    However, I'm not sure whether I understand your specs completely as extracting the element id in jQuery is as trivial as getting the data attribute: $('.foo').attr('id');.

    You might be interested in Caniuse.com, a browser compatibility site for web technologies.

    If XHTML is an issue to you, you might also be interested in how to use custom data attributes in XHTML: see here for a discussion on SO and here for an XHTML-compatible approach using namespaces.

    0 讨论(0)
提交回复
热议问题