How to store data in the DOM ? Last Updated : 18 May, 2021 Comments Improve Suggest changes Like Article Like Report 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. Syntax: $(selector).data(name) Attribute values: 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. HTML <!DOCTYPE HTML> <html> <head> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"> </script> </head> <body style="text-align:center;" id="body"> <h2 style="color:green">GeeksforGeeks</h2> <p><b>Enter the value to store:</b></p> <input type="text" id="data" name="input"><br/> <br/> <button id="b1">Store entered data</button> <button id="b2">View data </button><br/><br/> <div id="display"></div> <script> $(document).ready(function(){ // We are setting user data to data tag $("#b1").click(function(){ var d=($("#data").val()); $("#data").data("userdata",d); }); //Displaying data after accessing from data tag $("#b2").click(function(){ $("#display").html($("#data").data("userdata")) ; }); }); </script> </body> </html> Output: data() method Comment More infoAdvertise with us Next Article How to store data in the DOM ? F faizamu19 Follow Improve Article Tags : Web Technologies HTML JQuery HTML-DOM jQuery-Selectors jQuery-Questions +2 More Similar Reads How to store data to DOM ? In this article, we will learn how to store data in DOM. You can use data-* attribute to store data or information on DOM. The data-* attributes can be used to define our own custom data attributes. It is used to store custom data in private on the page or application.There are mainly 2 parts of the 2 min read How to store an array in localStorage ? To store an array in localStorage refers to saving an array of data in the web browserâs storage that persists across sessions. This is useful for keeping data, like user preferences or temporary information, accessible even after refreshing the page or reopening the browser.What is Javascript local 3 min read How to Save Data in Local Storage in JavaScript? LocalStorage is a client-side web storage mechanism provided by JavaScript, which allows developers to store key-value pairs directly in the user's browser. Unlike cookies, LocalStorage is persistentâdata stored remains even after the browser is closed and reopened, making it ideal for retaining use 2 min read How to Store Data in Local Storage using AngularJS ? Angular JS is a typescript-based web application framework. It is supported by the Angular team of Google and open-source developers. It is a component-based framework allowing the developers to reuse the components created. It is well-suited for large and complex applications because of its well-de 5 min read How are DOM utilized in JavaScript ? What is DOM The document object Model (DOM) represents the full HTML document. When an HTML document is loaded within the browser, it becomes a document object. The root element represents the HTML document, its properties, and its methods. With the assistance of a document object, we will add dynam 3 min read Like