Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to remove html element with the help of jQuery

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 287
    Comment on it

    It is very easy to remove html elements, we can do this with the help of jQuery . jQuery have two method for doing this one is jQuery remove() method and the other one is jQuery empty() method. Below i am explaining jQuery remove() method.

    jQuery remove() Method

    This method removes the element which we have selected, it also removes all the child elements which are selected html element have.

    syntax:-

    selector.remove( expr )

    selector − it is used to select html elements in which jquery has to be applied by using either id , class or html elements.

    expr :-This is a optional parameter which is used to filter elements which we want to remove.

    Below is html code for jquery remove() method example.

    <div id="remove_div" style="height:150px;width:350px;border:2px solid #000;background-color:grey;">
    
    <p>Lorem ipsum Lorem ipsum Lorem ipsum .</p>
    <p>Lorem ipsum Lorem ipsum Lorem ipsum .</p>
    <p>Lorem ipsum Lorem ipsum Lorem ipsum .</p>
    
    </div>
    
    
    <button>Remove</button>

    Below is jquery remove method() code :-

    $(document).ready(function(){
        $("button").click(function(){
            $("#remove_div").remove();
        });
    });

    Working demo:-https://jsfiddle.net/yhe84n75/2/

    In above example $("#remove_div").remove();  this jQuery remove method is removing whole div with the help of  id i.e remove_div which we give to the div which we want to remove when we click on the Remove 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: