remove method in jQuery with examples

1. remove() method removes the set of matched elements from the DOM structure.
2. remove() is similar to empty() method, which removes element and everything inside it from the DOM structure.
3. Unlike detach() method remove() does not keep information of elements being removed.

Example 1 :

        <script type="text/javascript" src=""> 
        <script type="text/javascript">
            $(document).ready(function () {
                $("#removeId").click(function () {
                $("#removeClass").click(function () {
        <p id="targetP" class="default">This is p element.</p>
        <div id="targetDiv" class="default">This is div element.</div><br />
        <input type="button" id="removeId" value="Remove using Id selector"/>
        <input type="button" id="removeClass" value="Remove using Class selector"/>
        <input type="button" id="reset" value="Reset" onclick="location.reload()" />
Demo :

In above example, we have rendered a paragraph and an div element. We have created two buttons, on click of both we are removing the elements from the DOM structure using remove() method. For removing we are using id and class selecotor both.


Post a Comment