Example of .detach() in jQuery
May 01, 2013
.detach() in Jquery is called on any event. .detach() detaches the element from HTML Document and that element disappears. Synatx is
.detach()
<!DOCTYPE html> <html> <head> <style>p { background:yellow; margin:6px 0; } </style> <script src="http://code.jquery.com/jquery-1.9.1.js"></script> </head> <body> <p>This is jQuery page.</p> <button id="detach">Detach paragraphs</button> <script> var p; $("#detach").click(function(){ $("p").detach(); }); </script> </body> </html>
Output