Empty and Remove Method in jQuery

 <!DOCTYPE html>

<html lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Empty and Remove Method in jQuery</title>
<style>
    body {
        font-family: arial
    }

    #box {
        background: lightgreen;
        padding: 10px;
        border: 1px solid #000;
    }
</style>

<body>
    <h1>jQuery Empty & Remove Methods</h1>
    <div id="box">
        <h2>Test Box</h2>
        <p>Lorem ipsum <span>dolor, sit amet</span> consectetur adipisicing elit. Obcaecati, magnam non! Blanditiis,
            odio! Autem laborum, laboriosam debitis optio impedit veritatis maxime voluptate ipsa necessitatibus sunt
            deserunt vero inventore esse totam.</p>
    </div>
    <br>
    <button id="emptyHeading">Empty Heading</button>
    <button id="emptyBtn">Empty</button>
    <button id="removeHeading">Remove Heading</button>
    <button id="removeBtn">Remove</button>
    <script src="js/jquery-3.7.1.min.js"></script>
    <script>
        $(document).ready(function () {
            $("#emptyHeading").click(function () {
                $("#box h2").empty();
            });

            $("#emptyBtn").click(function () {
                $("#box").empty();
            });

            $("#removeBtn").click(function () {
                $("#box").remove();
            });

            $("#removeHeading").click(function () {
                $("h1").remove();
            });

        });
    </script>
</body>

</html>







Comments

Popular posts from this blog

Basic Syntax in jQuery

Event "Target" Property in jQuery