HTML data attributes
Last updated
Was this helpful?
Last updated
Was this helpful?
Part of HTML5 includes the data-*
attribute: a way for us to attach arbitrary data to an element. If we define a div element with a data-name="A Great Div"
attribute, then our dataset
property inside our node will be an object with a name
key holding the string "A Great Div". For custom element-associated metadata, they are a great solution.
Play around with it. Look up the data-*
attribute and explore the dataset
property inside of a node. See how you can create data attributes of your own and retrieve the data they hold from the dataset object.
What happens if you have a property with a name like this?
Won't get confused with styling like CSS classes
Its defined in the
supported by