简体   繁体   中英

why do we need prefix “data” for custom data attributes in html5

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM