수

.detach ([selector])

· 2017-09-02 (토) 12:21:03 · 2001

.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>

|
댓글을 작성하시려면 로그인이 필요합니다.

개발자팁

5,403건

개발과 관련된 유용한 정보를 공유하세요. 질문은 QA에서 해주시기 바랍니다.

+
분류 제목 글쓴이 날짜 조회
jQuery
[jQuery]
17-09-09 조회 1,867
jQuery 17-09-09 조회 2,695
jQuery 17-09-09 조회 4,084
PHP 17-09-08 조회 6,140
기타 17-09-08 조회 2,423
기타 17-09-08 조회 2,246
기타 17-09-08 조회 2,538
jQuery 17-09-07 조회 2,145
jQuery 17-09-07 조회 1,856
jQuery 17-09-07 조회 2,648
jQuery 17-09-06 조회 2,340
jQuery
[jQuery]
17-09-06 조회 2,099
jQuery 17-09-06 조회 2,380
jQuery
[jQuery]
17-09-05 조회 1,784
jQuery
[jQuery]
17-09-05 조회 2,066
jQuery
[jQuery]
17-09-05 조회 1,753
jQuery
[jQuery]
17-09-02 조회 1,687
jQuery 17-09-02 조회 2,002
jQuery 17-09-02 조회 2,098
jQuery 17-09-01 조회 2,095
jQuery 17-09-01 조회 2,250
jQuery 17-09-01 조회 1,976
jQuery 17-08-31 조회 2,336
jQuery 17-08-31 조회 2,449
jQuery 17-08-31 조회 1,881
PHP 17-08-31 조회 3,301
jQuery 17-08-29 조회 1,885
jQuery 17-08-29 조회 2,072
jQuery 17-08-29 조회 2,147
jQuery 17-08-27 조회 2,013