Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • jQuery detach( ) method

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 206
    Comment on it

    This method is used to remove the selected elements( i.e all text and child nodes as well ). If we want to reinsert that removed elements , we can do that easily because it keeps a copy of the removed elements.

    Syntax :

    $(selector).detach()
    

    HTML Code :

    <!DOCTYPE html>
    <html>
    <head>
    </head>
    <body>
    <p>This is first line.</p>
    <p>This is second line.</p>
    <button>Remove all p elements</button>
    </body>
    </html>
    

    jQuery Code :

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
      $("button").click(function(){
        $("p").detach();
      });
    });
    </script>
    

    Output :
    Befor click on button :

    This is first line.

    This is second line.

    After click on button :// all p tag elements will be removed

 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: