.detach ([selector])
.detach ([selector])
설명 : 일치하는 요소 세트를 DOM에서 제거하십시오.
.detach ([selector])
선택자
유형 : 선택기
제거 할 일치하는 요소 집합을 필터링하는 selector 식입니다.
이 .detach()메소드는 제거 된 요소와 관련된 모든 jQuery 데이터 .remove()를 .detach()유지 한다는 점을 제외하고 는 동일 합니다. 이 메소드는 나중에 제거 된 요소가 DOM에 다시 삽입 될 때 유용합니다.
예:
DOM에서 모든 단락 분리
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>detach demo</title>
<style>
p {
background: yellow;
margin: 6px 0;
}
p.off {
background: black;
}
</style>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<p>Hello</p>
how are
<p>you?</p>
<button>Attach/detach paragraphs</button>
<script>
$( "p" ).click(function() {
$( this ).toggleClass( "off" );
});
var p;
$( "button" ).click(function() {
if ( p ) {
p.appendTo( "body" );
p = null;
} else {
p = $( "p" ).detach();
}
});
</script>
</body>
</html>
게시판 목록
개발자팁
질문은 QA에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 4826 | jQuery | 8년 전 | 1672 | ||
| 4825 | JavaScript | 8년 전 | 2739 | ||
| 4824 | jQuery | 8년 전 | 1462 | ||
| 4823 | jQuery | 8년 전 | 1726 | ||
| 4822 | jQuery | 8년 전 | 1810 | ||
| 4821 | jQuery | 8년 전 | 1637 | ||
| 4820 | jQuery | 8년 전 | 1647 | ||
| 4819 | jQuery | 8년 전 | 1325 | ||
| 4818 | jQuery | 8년 전 | 1969 | ||
| 4817 | jQuery | 8년 전 | 2407 | ||
| 4816 | jQuery | 8년 전 | 1703 | ||
| 4815 | jQuery | 8년 전 | 1420 | ||
| 4814 | jQuery | 8년 전 | 1839 | ||
| 4813 | jQuery | 8년 전 | 5411 | ||
| 4812 | 기타 | 8년 전 | 3163 | ||
| 4811 | jQuery | 8년 전 | 1542 | ||
| 4810 | jQuery | 8년 전 | 1714 | ||
| 4809 | jQuery | 8년 전 | 1802 | ||
| 4808 | PHP |
|
8년 전 | 5084 | |
| 4807 | node.js |
|
8년 전 | 4116 | |
| 4806 | jQuery | 8년 전 | 2215 | ||
| 4805 | jQuery | 8년 전 | 1652 | ||
| 4804 | jQuery | 8년 전 | 1201 | ||
| 4803 | jQuery | 8년 전 | 1910 | ||
| 4802 | jQuery | 8년 전 | 1417 | ||
| 4801 | jQuery | 8년 전 | 1522 | ||
| 4800 | jQuery | 8년 전 | 1742 | ||
| 4799 | jQuery | 8년 전 | 1984 | ||
| 4798 | jQuery | 8년 전 | 1520 | ||
| 4797 | jQuery | 8년 전 | 1455 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기