Introduction:
Sometime it is needed to empty
the div or remove the div while working with ASP.NET and Jquery. In jQuery
there are two functions empty() function and remove() which are used to empty
or remove the div.
In this article I will explain
how to use jQuery empty() function and remove() function
with examples. In jQueryboth
empty() and remove() functions are used to remove the elements. Empty()
function in jQuery is used remove inside content of div
element and remove() function is used to remove complete div element.
By using empty() function we can remove inside content
of div element, but div will be there(only content will be deleted).
and remove() function will remove complete div .
The following code will described the use of empty() & remove()
methods:
<script type="text/javascript">
$(function
() {
$('#btnEmpty').click(function () {
$('#pdiv').empty();
});
$('#btnRemove').click(function () {
$('#pdiv').remove();
});
})
</script>
Full
Source Code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery Empyt() and Remove()
Functions Examples</title>
<script type="text/javascript"
src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function
() {
$('#btnEmpty').click(function () {
$('#pdiv').empty();
});
$('#btnRemove').click(function () {
$('#pdiv').remove();
});
})
</script>
</head>
<body>
<center>
<fieldset style="width:350px">
<legend><strong> Empty()
and Remove() Functions in jQuery</strong></legend>
<div id="pdiv" style="border:1px solid red; padding:10px">
<div> Remove or Empty Div using Empty()
and Remove() Functions in jQuery</div>
</div><br />
<input type="button"
id="btnEmpty"
value="Empty
Div" />
<input type="button"
id="btnRemove"
value="Remove
Div" />
</fieldset></center>
</body>
</html>
0 comments:
Post a Comment