From jQuery JavaScript Library
« Back to Internals
jQuery.removeData( elem )
Remove the expando attribute that allows data storage on an element.
This is the complement function to
jQuery.data(elem) which is called as necessary by
jQuery.data(elem, name, value).
Arguments:| elem | Element | |
|---|
| Element to delete the data store from. |
Examples:| Name | Type |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(){
var adiv = $("div").get(0);
$("span:eq(0)").text("" + jQuery.data(adiv, "test1"));
jQuery.data(adiv, "test1", "VALUE-1");
jQuery.data(adiv, "test2", "VALUE-2");
$("span:eq(1)").text("" + jQuery.data(adiv, "test1"));
jQuery.removeData(adiv);
$("span:eq(2)").text("" + jQuery.data(adiv, "test1"));
$("span:eq(3)").text("" + jQuery.data(adiv, "test2"));
});
</script>
<style>
div { margin:2px; color:blue; }
span { color:red; }
</style>
</head>
<body>
<div>value1 before creation: <span></span></div>
<div>value1 after creation: <span></span></div>
<div>value1 after removal: <span></span></div>
<div>value2 after removal: <span></span></div>
</body>
</html>
jQuery.removeData( elem, name )
Removes just this one named data store.
This is the complement function to
jQuery.data(elem, name, value).
Arguments:| elem | Element | |
|---|
| Element to delete the named data store property from. |
| name | String | |
|---|
| The name of the data store property to remove. |
Examples:| Name | Type |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(){
var adiv = $("div").get(0);
$("span:eq(0)").text("" + jQuery.data(adiv, "test1"));
jQuery.data(adiv, "test1", "VALUE-1");
jQuery.data(adiv, "test2", "VALUE-2");
$("span:eq(1)").text("" + jQuery.data(adiv, "test1"));
jQuery.removeData(adiv, "test1");
$("span:eq(2)").text("" + jQuery.data(adiv, "test1"));
$("span:eq(3)").text("" + jQuery.data(adiv, "test2"));
});
</script>
<style>
div { margin:2px; color:blue; }
span { color:red; }
</style>
</head>
<body>
<div>value1 before creation: <span></span></div>
<div>value1 after creation: <span></span></div>
<div>value1 after removal: <span></span></div>
<div>value2 after removal: <span></span></div>
</body>
</html>