jQuery removeData() Method

The jQuery removeData() method can be used to remove all or specified previously set data. The data is previously set with the jQuery Data() method.

jQuery removeData() Method

Syntax

The syntax of this method is given below:-

Remove All attached data of an element
$(selector).removeData()
Remove Specified Attached data of an element
$(selector).removeData(keyname)

Description of the Parameters

The description of the parameters is given below.

Parameter Name Description
selector Specify to select the element and remove the set data. You can use tag name, class name, or id of the elements to select.
keyname It is the name of data to identify with its set value.
value It is the value specified for the data.

jQuery removeData() Method to Remove All Attached Data

If you want to remove all the attached data from the selected element, you have to use the below example. The example first sets the two data using the data() method. After that, it removes all the data using the jQuery removeData() method without specifying any parameter.

Example

Test it Live

Output


You have to click the set button given above to set the data. It sets two data which you can check in the alert box. Now, click the remove button to remove all the data attached to the selected element.

Remove Specified Attached Data Using Method

You can also remove only the specified data using the jQuery removeData() method. Specify the data contains the keyname and its value. After that, remove the specified data by specifying the parameter withing the removeData() method.

Example

Test it Live

Output


When you click the set button, it first set the data for the selected element. After that, click the remove button to remove the specified keyname data.

You may also like to read

I hope you like this tutorial on jQuery removeData() Method. If you have any queries regarding the tutorial, please comment below.

References