jQuery विविध डेटा () विधि
उदाहरण
<div> तत्व में डेटा संलग्न करें, फिर डेटा पुनर्प्राप्त करें:
$("#btn1").click(function(){
$("div").data("greeting", "Hello World");
});
$("#btn2").click(function(){
alert($("div").data("greeting"));
});
परिभाषा और उपयोग
डेटा () विधि चयनित तत्वों से डेटा संलग्न करती है, या डेटा प्राप्त करती है।
युक्ति: डेटा निकालने के लिए, removeData() विधि का उपयोग करें।
एक तत्व से डेटा लौटाएं
चयनित तत्व से संलग्न डेटा लौटाता है।
वाक्य - विन्यास
$(selector).data(name)
Parameter | Description |
---|---|
name | Optional. Specifies the name of data to retrieve. If no name is specified, this method will return all stored data for the element as an object |
एक तत्व के लिए डेटा संलग्न करें
चयनित तत्वों में डेटा संलग्न करें।
वाक्य - विन्यास
$(selector).data(name,value)
Parameter | Description |
---|---|
name | Required. Specifies the name of data to set |
value | Required. Specifies the value of data to set |
किसी वस्तु का उपयोग करके किसी तत्व को डेटा संलग्न करें
नाम/मान जोड़े के साथ किसी ऑब्जेक्ट का उपयोग करके चयनित तत्वों को डेटा संलग्न करें।
वाक्य - विन्यास
$(selector).data(object)
Parameter | Description |
---|---|
object | Required. Specifies an object containing name/value pairs |