Why are use the remove method in JQuery?

Asked 28-Jul-2021
Viewed 190 times

1 Answer


1

 The jQuery remove () method is used to remove data and event of selected elements from html page. This remove () remove everything inside it (including all texts and child nodes) of selected elements.
Syntax

 $(selector).remove()
 $(selector).remove(“class selector, id selector, tag name selector, etc)
Example

<!DOCTYPE html>
<html>
<head>
    <script src='https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js'></script>
    <script>
        $(document).ready(function () {
            $('p').click(function () {
                $(this).remove();
            });
        });
    </script>
    <style>
        p {
            background-color:orange;
            color:white;
        }
    </style>
</head>
<body>
    <h1>Click any paragraph for remove from html page</h1>
    <p >MindStick pvt ltd in allahabad 1</p>
    <p >MindStick pvt ltd in allahabad 2</p>
    <p >MindStick pvt ltd in allahabad 3</p>
    <p >MindStick pvt ltd in allahabad 4</p>
    <p >MindStick pvt ltd in allahabad 5</p>
    <p >MindStick pvt ltd in allahabad 6</p>
    <p >MindStick pvt ltd in allahabad 7</p>
    <p >MindStick pvt ltd in allahabad 8</p>
</body>
</html>
Why are use the remove method in JQuery?