AngularJS gives the option of, but does not use the data- prefix in their examples or mandate the use of it. Should I include the data- prefix in my project and why?
Is it still valid HTML if I don't use data-*?
The data-* attributes allow us to embed custom attributes on all HTML elements. These are completely ignored by the user agent. The data stored can be used in JavaScript of the page. We can also use these data attributes to style our elements.
The data-* attribute is used to store custom data private to the page or application. The data-* attribute gives us the ability to embed custom data attributes on all HTML elements.
Certainly. Entities are converted into their values when parsed.
The attribute is most useful with A, AREA, LINK, and IMG elements, where it provides a title for the linked or embedded resource.
Many libraries like knockout, angular etc. do not use the data- prefix.
Knockout uses data-*: "<span data-bind="text: myMessage">
"
Angular uses data-*: "the directive can be prefixed with x-, or data- to make it HTML validator compliant" (shame they don't understand that it is for compliance with HTML and not with the validator).
Should i include the data- prefix ?
Yes, you should write valid HTML. If you are making up attributes, use data-
ones.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With