수

.detach ([selector])

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

.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에서 해주시기 바랍니다.

+
분류 제목 글쓴이 날짜 조회
JavaScript 17-07-03 조회 3,644
PHP 17-07-03 조회 2,408
MySQL 17-06-30 조회 5,515
PHP 17-06-20 조회 2,507
PHP 17-06-20 조회 2,738
PHP 17-06-20 조회 2,815
MySQL 17-06-17 조회 2,760
PHP 17-06-17 조회 2,589
PHP 17-06-17 조회 2,652
PHP 17-06-14 조회 2,133
PHP 17-06-14 조회 2,159
PHP 17-06-14 조회 2,320
PHP 17-06-13 조회 2,393
PHP 17-06-13 조회 2,530
PHP 17-06-13 조회 2,171
PHP 17-06-12 조회 2,117
PHP 17-06-12 조회 2,314
PHP 17-06-12 조회 2,053
Mobile 17-06-09 조회 1.1만
PHP 17-06-08 조회 2,631
PHP 17-06-08 조회 2,179
PHP 17-06-08 조회 2,496
OS 17-06-08 조회 7,800
PHP 17-06-07 조회 2,529
PHP 17-06-07 조회 2,559
PHP 17-06-07 조회 6,015
MySQL 17-06-07 조회 4,809
OS 17-06-06 조회 3,608
PHP 17-06-06 조회 2,808
PHP 17-06-06 조회 2,724