This article mainly introduces the usage of the removeData() method in jQuery. It analyzes the technique of removeData() method to remove the specified data of matching elements in the form of examples. It has certain reference value. Friends who need it can refer to it
The example in 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 to the data() method.
Grammar structure one:
$(selector).removeData(name)
Parameter list:
<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="//www.jb51.net/" /> <title>脚本之家</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","脚本之家欢迎您"); }); $("#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>
Example code:
The above code can be specified through the data() method The element appends data, then uses the removeData() method to delete the data, and finally detects whether the data has been deleted.
The above is the entire content of this chapter. I hope it will be helpful to everyone’s jQuery programming. For more related tutorials, please visit jQuery Video Tutorial!