HTML Editor
<!DOCTYPE html> <html lang="en-US"> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> </head> <body> <h1>jQuery remove() vs detach() Methods</h1> <p><strong>Note</strong>: Remove will not carry the event handlers. Whereas, Detach will carry the event handlers.</p> <p id="myRemove">Remove - Click 'Remove' button and click on this paragraph.</p> <p id="myDetach">Detach - Click 'Detach' button and click on this paragraph.</p> <button id="btn1">Remove</button> <button id="btn2">Detach</button> <script> $(document).ready(function(){ $("#btn1").click(function(){ $("body").append($("#myRemove").remove()); }); $("#btn2").click(function(){ $("body").append($("#myDetach").detach()); }); $("p").click(function(){ alert("You click"); }); }); </script> </body> </html>
OUTPUT
×

Save as Private