Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Different types of jQuery Remove Elements

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 473
    Comment on it

    With the help of jQuery, its easy to remove any html within a single click. jQuery is having 2 methods to remove html elements.

     

    1. remove() - Removes the selected element (and its child elements)
    2. empty() - Removes the child elements


    jQuery remove() Method

    This method removed the html element with its child element.

    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> // calling jquery min js script
    
    <script>
    $(document).ready(function(){
        $("button").click(function(){
            $("#div1").remove();  // function to remove html of div id =1
        });
    });
    </script>
    </head>
    
    
    <div id="div1" style="height:50px;width:50px;bbackground-color:blue;"> // html of the text
    
    text 1
    <p>text 2</p>
    </div>
    
    
    <button>Remove above html</button> // button
    

    jQuery empty() Method

    The jQuery empty() method empty the selected element (removes only child HTML element)

     

    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
        $("button").click(function(){
            $("#div1").empty(); // function to empty the di of id=1
        });
    });
    </script>
    </head>
    <body>
    
    <div id="div1" style="height:50px;width:50px;background-color:blue;">
    
    text 1
    <p>text 2</p>
    
    </div>
    <br>
    
    <button>Empty the html box</button> // button
    
    

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: