1.

What Is The Use Of Jquery.data()?

Answer»
  • jQuery.data() is used to set/return arbitrary data to/from an element.
  • SYNTAX: jQuery.data(element, key, value)
  • “element” is the DOM element to which the data is associated.
  • “key” is an arbitrary name of the piece of data.
  • “value” is value of the specified key.
  • Suppose we WANT to set the data for a span element:

jQuery.data(span, “item”, { val1: 10, val2: "myitem" });

If we want to RETRIEVE the data related to div element and set it to label’s data:

$("label:val1").TEXT(jQuery.data(div, "item").val1);
$("label:val2").text(jQuery.data(div, "item").val2);

jQuery.data(span, “item”, { val1: 10, val2: "myitem" });

If we want to retrieve the data related to div element and set it to label’s data:

$("label:val1").text(jQuery.data(div, "item").val1);
$("label:val2").text(jQuery.data(div, "item").val2);



Discussion

No Comment Found