Friday, July 18, 2014

Javascript empty function

In this article i am going to show how to clear contents in web page.Empty() is used remove the content of all particular elements like <div>,<p> etc.



Live DemoDownload Script


Step 1:
Need library file to perform empty action.Please copy and Paste below library file.
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>

jQuery Empty Function

<script>
        $(document).ready(function(){
          $("#removebtn").click(function(){ //button id
            $("#para").empty(); //div id
          });
        });
        </script>

HTML code for Javascript event

<div id="para" style="border:1px solid #ccc;height:160px;width:400px; padding:5px;"> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining</div>
<button id="removebtn" style="background:#0099FF; border:none; height:25px; margin:5px; color:#fff; cursor:pointer">Run Empty Method</button>

Please share your comments and feedback.Thanks.Please subscribe my updates via email.

2 comments:

  1. That is the jQuery way. Straight Javascript way does not require jQuery library.

    http://jsfiddle.net/Eu9rS/

    ReplyDelete