jQuery Misc data() Method

## jQuery Tutorial

jQuery HOME jQuery Intro jQuery Install jQuery Syntax jQuery Selectors jQuery Events

## jQuery Effects

jQuery Hide/Show jQuery Fade jQuery Slide jQuery Animate jQuery stop() jQuery Callback jQuery Chaining

## jQuery HTML

jQuery Get jQuery Set jQuery Add jQuery Remove jQuery CSS Classes jQuery css() jQuery Dimensions

## jQuery Traversing

jQuery Traversing jQuery Ancestors jQuery Descendants jQuery Siblings jQuery Filtering

## jQuery AJAX

jQuery AJAX Intro jQuery Load jQuery Get/Post

## jQuery Misc

jQuery noConflict()

## jQuery Examples

jQuery Examples jQuery Quiz jQuery Certificate

## jQuery References

jQuery Selectors jQuery Events jQuery Effects jQuery HTML/CSS jQuery Traversing jQuery AJAX jQuery Misc jQuery Properties

# jQuery Misc data() Method

jQuery Misc Methods

## Example

Attach data to a <div> element, then retrieve the data:

$("#btn1").click(function(){
$("div").data("greeting", "Hello World");
});
$("#btn2").click(function(){
alert($("div").data("greeting"));
});
Try it yourself »

## Definition and Usage

The data() method attaches data to, or gets data from, selected elements.

Tip: To remove data, use the removeData() method.

## Return Data from an Element

Returns attached data from a selected element.

## Syntax

$(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

## Attach Data to an Element

Attach data to selected elements.

## Syntax

$(selector).data(name,value)

Parameter | Description
--- | ---
name | Required. Specifies the name of data to set
value | Required. Specifies the value of data to set

## Attach Data to an Element Using an Object

Attach data to selected elements using an object with name/value pairs.

## Syntax

$(selector).data(object)
Try it yourself »

Parameter | Description
--- | ---
object | Required. Specifies an object containing name/value pairs

jQuery Misc Methods

## Your suggestion:

Your E-mail (optional):

Page address:

Description:

Close [X]

## Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

## WEB HOSTING

Best Web Hosting UK Reseller Hosting Wow! $5 SSD Hosting

## WEB BUILDING

Download XML Editor
FREE Website BUILDER FREE Website Creator

## WEB RESOURCES

Web Statistics Web Validation

## SHARE THIS PAGE