Introduction:

Here we are going to explain what is empty() method or how to use empty() method or why use empty() method or how to remove all child content or element from selected element in jQuery with example.

Description: 

The jQuery empty() method is used to remove all child element or nodes and content from the selected elements. This method doesn't remove the element itself.  

Syntax:

$(selector).empty()


  • Example of jQuery empty() method

Let's see an example to of jQuery empty() method.

 <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>jquery keypress tutorial</title>
    <script src="Scripts/jquery-1.8.2.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("button").click(function () {
                $("div").empty();
            });
        });
    </script>
 
</head>
<body>
    <div style="height:150px;background-color:yellow">
        <p style="width:400px;">
    <span>
        Conversion. An intuitive         analytics suite provides granular data on ROI, conversions, influence, and         contributor performance.
        Growth. Data strategists and         distribution experts ensure content reaches target, global audiences.
        </span> </p>
    </div>
    <p>This content is written outside the div.</p>
    <button>empty() all content of div element.</button>
</body>
</html>

 

As shown in the above program,  When user click on button then all child content remove from  div element.

Output:

   use jQuery empty() method


    I hope it will help to you.

 

0 comments


Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

You may also like