jquery detach() method
Translation results:
detach
English [dɪˈtætʃ] US [dɪˈtætʃ]
vt. Dispatch; separate, take apart; assign; make transcendent
jquery detach() methodsyntax
Function: The detach() method removes the selected elements, including all text and child nodes. This method retains the matching elements in the jQuery object so that they can be used again in the future. detach() will retain all bound events and attached data, which is different from remove().
Syntax: $(selector).detach()
jquery detach() methodexample
<html> <head> <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ $("p").detach(); }); }); </script> </head> <body> <p>This is a paragraph.</p> <button>删除 p 元素</button> </body> </html>
Click the "Run instance" button to view the online instance