AngularJS documentation says Optionally the directive can be prefixed with x-, or data- to make it HTML validator compliant.
.
Example markup:
<input ng-model="name">
data-
: <input data-ng-model="name">
x-
: <input x-ng-model="name">
The x-
prefix is faster to type than data-
, but the tutorials I have seen used either no prefix or data-
, so my question is: are there any reasons I might want to use data-
rather than x-
?
data-* attributes allow us to store extra information on standard, semantic HTML elements without other hacks such as non-standard attributes, or extra properties on DOM.
Attribute data is data that have a quality characteristic (or attribute) that meets or does not meet product specification. These characteristics can be categorized and counted.
Custom attributes are attributes that are not part of the standard HTML5 attributes but are explicitly created. They allow us to add our own information to HTML tags. These are not specific and can be used with all the HTML elements.
In that case, you can use the getAttribute() method. The getAttribute() method will return the string value of the specified attribute. Alternatively, you can also access attributes using the getNamedItem() method.
The advantage of using a data-
prefix rather than an x-
prefix is that data-
prefixes are guaranteed to remain available to authors as they like, whereas an x-
prefix might one day be used for a browser-specific purpose, possibly conflicting with yours. Note that x-
are not conforming according to HTML5.
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