Use the data-* attribute to embed custom data:
The data-* attributes is used to store custom data private to the page or application.
The data-* attributes gives us the ability to embed custom data attributes on all HTML elements.
The stored (custom) data can then be used in the page's JavaScript to create a more engaging user experience (without any Ajax calls or server-side database queries).
The data-* attributes consist of two parts:
Note: Custom attributes prefixed with "data-" will be completely ignored by the user agent.
The numbers in the table specify the first browser version that fully supports the attribute.
Attribute | |||||
---|---|---|---|---|---|
data-* | 4.0 | 5.5 | 2.0 | 3.1 | 9.6 |
The data-* attributes are new in HTML5.
Value | Description |
---|---|
somevalue | Specifies the value of the attribute (as a string) |
HTML Tutorial: HTML Attributes
HTML DOM Reference: HTML DOM getAttribute() Method