Javascript examples for jQuery Method and Property:detach
The detach() method removes the selected elements, including all text and child nodes, keeps its event handler.
The following code shows how to Remove all <p> elements:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("p").detach(); });/* ww w .j a v a2 s.co m*/ }); </script> </head> <body> <p>This is a paragraph.</p> <p>This is another paragraph.</p> <button>Remove all p elements</button> </body> </html>