How to use Misc Data() Method in JQuery

In this article I am going to explain about Misc data() method in jquery.
  • 2352

jQuery Misc Data() Method

jquery Misc Data() method use for get the data from an element or set the data to an element.

Syntax for set the data to an element

$(selector).data(name,value)

Syntax for get the data from an element.

$(selector).data(name)

 

Example // Its example will display two button first button for set  the data to an element and second for get data from element.

 

<html>

<head>

    <script type="text/javascript" src="jquery.js"></script>

    <script type="text/javascript">

        $(document).ready(function () {

            $("#bt1").click(function () {

                $("p").data("prabh", "Hello Friends");

            });

            $("#bt2").click(function () {

                alert($("p").data("prabh"));

            });

        });

    </script>

</head>

<body>

    <button id="bt1">

        Get</button><br />

    <button id="bt2">

        Set</button>

    <p>

    </p>

</body>

</html>

 

Output

 

 getset.jpg

 

You may also want to read these related articles: here
 
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 
© 2020 DotNetHeaven. All rights reserved.