dataatribuutteja
Data attributes, also known as data attributes or custom data attributes, are a feature in HTML that allows developers to store extra information on standard, semantic HTML elements without other hacks such as non-standard attributes, extra properties on DOM, or Node.setUserData(). They are used to embed custom data in HTML elements, which can then be accessed and manipulated using JavaScript. Data attributes are prefixed with "data-" and can be used to store any type of data, such as strings, numbers, or JSON objects.
The syntax for data attributes is straightforward. They are added to HTML elements as attributes, with the
<div data-user-id="12345" data-user-name="John Doe"></div>
In this example, the "data-user-id" and "data-user-name" attributes store the user's ID and name, respectively. These
var userId = document.querySelector('div').dataset.userId;
var userName = document.querySelector('div').dataset.userName;
Data attributes are widely used in web development for various purposes, such as storing configuration data,