Javatpoint Logo
Javatpoint Logo

jQuery removeData() method

The removeData() method is used to remove the data set previously using the data() method. It is an inbuilt method in jQuery. The data() method is used to attach and get data from the selected elements.

Syntax

The selector in the above syntax is the selected element whose data is to be removed. The removeData() accepts an optional parameter, which is defined as follows -

name: It is the data name need to be removed. It is an optional parameter. This parameter is used to remove the particular value. If it is not specified, the removeData() method will remove all stored data associated with the selected element.

Let's see an illustration to understand the working of the removeData() method.

Example1

It is an example of using the removeData() method. In this example, we are removing the data added by the data() method with or without using the optional value of the removeData() method.

Here, there is a paragraph element with id = "p1". There are also three buttons that add or remove the data. When user will click the first button, the data will be added to the paragraph with id = "p1". On clicking the second button, the removeData() method will trigger and remove the specific data "name" added using the data() method. And on clicking the third button, the method will remove all stored data associated with the selected element.

Test it Now

Output

jQuery removeData() method

After clicking the Add data button, the output will be -

jQuery removeData() method

After clicking the 'Remove data using the optional parameter' button, the output will be -

jQuery removeData() method

After clicking the 'Remove data without using the optional parameter' button, the output will be -

jQuery removeData() method





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA