JQuery .detach()

(.detach()에서 넘어옴)

1 개요[ | ]

jQuery .detach()
  • DOM에서 선택된 요소들을 제거하는 jQuery 메소드

2 예시[ | ]

<script src='//code.jquery.com/jquery.min.js'></script>
<script>
var p;
$(function() {
	$( '#btn-detach' ).click(function() {
		if ( p ) return;
		p = $("p").detach();
	});
	$( '#btn-attach' ).click(function() {
		if( !p ) return;
		p.appendTo("div");
		p = null;
	});
});
</script>

<button id='btn-detach'>떼어내기</button>
<button id='btn-attach'>붙이기</button>
<div>
	<p>안녕</p>
	<span>Hello</span>
	<p>친구들</p>
</div>

3 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}