1

Is there any reason to use data-attribute for custom data attributes on html5 elements? I remember using custom data attributes without using data prefix and I think that did work alright.

Can someone please correct me.

Asaprab
  • 288
  • 1
  • 3
  • 16
afr0
  • 848
  • 1
  • 11
  • 29
  • 4
    possible duplicate of [Why should I prepend my custom attributes with "data-"?](http://stackoverflow.com/questions/2450585/why-should-i-prepend-my-custom-attributes-with-data) – Anthony Hilyard Jul 22 '15 at 21:10

1 Answers1

2

Abridged version of the answer by @Lachlan Hunt to the duplicate question:

  • It guarantees there will not be any clashes with extensions to HTML in future editions.
  • More convenient DOM API for accessing these attributes from scripts.
  • They provide a clear indication of which attributes are custom attributes, and which ones are standardised attributes.
Community
  • 1
  • 1
Nickolay
  • 31,095
  • 13
  • 107
  • 185
  • doesn't it make 'data' prefix irrelevant can that be done with using some other prefix as well. i've used many other custom html attributes. – afr0 Apr 06 '16 at 04:32
  • 1
    If you don't need the `dataset` APIs and pick a unique prefix, sure. – Nickolay Apr 06 '16 at 22:33