This article mainly introduces the usage of removeData() method in jQuery. It analyzes the technique of removeData() method to remove specified data of matching elements in the form of examples. It has certain reference value. Friends who need it can Refer to the following
The example of this article describes the usage of the removeData() method in jQuery. Share it with everyone for your reference. The specific implementation method is as follows:
This method can remove the specified data on the matching element.
The removeData() method has the opposite effect than the data() method.
Grammar structure one:
$(selector).removeData(name)
Parameter list:
<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="http://www.php.cn" /> <title>PHP中文网</title> <script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#add").click(function(){ $("p").data("mydata","PHP中文网欢迎您"); }); $("#show").click(function(){ $("p").text($("p").data("mydata")); }); $("#delete").click(function(){ $("p").removeData("mydata"); alert($("p").data("mydata")); }) }); </script> </head> <body> <p></p> <button id="add">向元素添加数据</button> <button id="show">显示添加的数据</button> <button id="delete">删除元素中的数据</button> </body> </html>
The above code can append data to the specified element through the data() method, and then use The removeData() method deletes data and finally detects whether the data has been deleted.
The above is the detailed content of Example sharing of removeData() usage in jQuery. For more information, please follow other related articles on the PHP Chinese website!