How to store data in the DOM ?
In this article, we will learn to store data to DOM elements.
If we want to save some data in an HTML tag, we can use the jQuery .data() method to store data which can also be retrieved later by using the same method.
- name: It defines the name of the data to be stored and is an optional parameter.
Note: If no name is specified, the .data() method returns all stored data for that particular element.
HTML code: Let us look at an example to understand how to store data to DOM using .data() method.
Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML course.