jquery removeData() method


  Translation results:

remove

UK[rɪˈmu:v] US[rɪˈmuv]

vt.Remove; expel; take off, take off; migrate

vi. Migrate, emigrate; leave

n. Distance, gap; move

data

UK[ˈdeɪtə] US[ˈdetə, ˈdætə, ˈdɑtə]

n. Data, material; plural of datum; [computer] data, information; value extracted from scientific experiments

jquery removeData() methodsyntax

Function: removeData() method deletes the data previously set through the data() method.

Syntax: $(selector).removeData(name)

Parameters:

ParameterDescription
name Optional. Specifies the name of the data to be deleted. If no name is specified, this method will remove all stored data from the selected element.

jquery removeData() methodexample

<html>
<head>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("#btn1").click(function(){
    $("div").data("greeting", "Hello World");
    alert("Greeting is: " + $("div").data("greeting"));
  });
  $("#btn2").click(function(){
    $("div").removeData("greeting");
    alert("Greeting is: " + $("div").data("greeting"));
  });
});
</script>
</head>
<body>
<button id="btn1">向 div 元素添加数据</button><br />
<button id="btn2">从 div 元素删除数据</button>
<div></div>
</body>
</html>
Run instance »

Click the "Run instance" button to view the online instance

Home

Videos

Q&A