728x90
SMALL
#jquery
#detach()
.detach()
.detach() removes the selected element from the document. Same as .remove() in that it removes, but .detach() saves the removed elements for reuse.
grammar
.detach( [selector ] )
for example
var jb = $( 'h1' ).detach();
will remove the h1 element from the document and store it in the variable jb.
example
Clicking the Cut button will cut the Dolor, and clicking the Paste button will paste it over the Ipsum.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery</title>
<script src="//code.jquery.com/jquery-3.3.1.min.js"></script>
<script>
jQuery( document ).ready( function() {
var jbDetach;
$( '#cut' ).click( function() {
jbDetach = $( '.b' ).detach();
} );
$( '#paste' ).click( function() {
$( '.a' ).before( jbDetach );
} );
} );
</script>
</head>
<body>
<h1>Lorem</h1>
<h2 class="a">Ipsum</h2>
<h2 class="b">Dolor</h3>
<button id="cut">Cut</button> <button id="paste">Paste</button>
</body>
</html>
728x90
LIST