Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

jQuery Remove() and Empty() Functions with Examples

Mar 18, 2015
Introduction

Here I will explain how to use
jQuery empty() function and remove() function with examples. In jQuery both 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.

Description:
  
In previous articles I explained 8 best audio player plugin examples, jQuery video player plugin examples,
jQuery Hover dropdown menu, jQuery bouncing menu example and many articles relating to AngularJS, jQuery, JavaScript and asp.net. Now I will explain how to use jQuery empty() function and remove() function with examples.

By using empty() function we can remove inside content of div element and remove() function will remove complete div element for that we need to write the code like as shown below


<script type="text/javascript">
$(function () {
$('#btnEmpty').click(function () {
$('#pdiv').empty();
});
$('#btnRemove').click(function () {
$('#pdiv').remove();
});
})
</script>

If you want to check it in complete example you need to write the code like as shown below


<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>
<form id="form1">
<div id="pdiv" style="border:1px solid red; padding:10px">
<div style="border:1px solid green; padding:10px"> Sample Content Child Div</div>
</div><br />
<input type="button" id="btnEmpty" value="Empty Div" />
<input type="button" id="btnRemove" value="Remove Div" />
</form>
</body>
</html>

Live Demo

For live demo try to click on Empty button and Remove button first empty button will remove inside div content and remove button will remove complete div



Sample Content Child Div



If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

1 comments :

Anonymous said...

dsf

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.