What is the purpose of the `data-*` attribute in HTML, and give an example of its usage?

Instruction: Describe the `data-*` attribute and provide a practical example.

Context: This question evaluates the candidate's knowledge of custom data attributes in HTML and their ability to implement them in real-world scenarios.

Official answer available

Preview the opening of the answer, then unlock the full walkthrough.

For instance, imagine we're developing a feature for a web application that requires a dynamic user interface, such as a dashboard for a social media analytics platform. In this scenario, we might need to display a list of posts with their respective engagement metrics (likes, shares, comments) and the user who posted it. Using the data-* attribute, we can attach these metrics directly to each post element in the HTML, making it straightforward to access and manipulate this...

Related Questions