YouTip LogoYouTip

Misc Data

# jQuery Miscellaneous data() Method [![Image 3: jQuery Miscellaneous Methods](#) jQuery Miscellaneous Methods](#) ## Example Attach data to a
element, then retrieve that data: $("#btn1").click(function(){ $("div").data("greeting", "Hello World"); }); $("#btn2").click(function(){ alert($("div").data("greeting")); }); [Try it Β»](#) * * * ## Definition and Usage The data() method attaches data to, or retrieves data from, selected elements. **Tip:** To remove data, use the [removeData()](#) method. * * * ## Return Data from an Element Returns the attached data from the selected element. ## Syntax $(_selector_).data(_name_) | Parameter | Description | | :--- | :--- | | _name_ | Optional. Specifies the name of the data to retrieve. If no name is specified, the method returns all stored data as an object. | * * * ## Attach Data to an Element Attaches data to the selected element. ## Syntax $(_selector_).data(_na_ _me,value_) | Parameter | Description | | :--- | :--- | | _name_ | Required. Specifies the name of the data to set. | | _value_ | Required. Specifies the value of the data to set. | * * * ## Attach Data to an Element Using an Object Attaches data to the selected element using an object containing name/value pairs. ## Syntax $(_selector_).data(_object_) [Try it Β»](#) | Parameter | Description | | :--- | :--- | | _object_ | Required. Specifies an object containing name/value pairs. | * * jQuery Miscellaneous Methods](#)
← Misc EachAjax Serializearray β†’