Home > Web Front-end > JS Tutorial > body text

Example sharing of removeData() usage in jQuery

巴扎黑
Release: 2017-06-20 10:39:06
Original
1015 people have browsed it

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:

name. Example code:
Parameter Description
Optional. Defines the name of the data to delete If no name is defined, this method will delete all stored data from the selected elements.
<!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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template