본문 바로가기
jquery

[jquery] detach 와 remove

by ponionq 2021. 1. 10.

detach

-선택한 요소를 DOM 요소에서 삭제(데이터와 이벤트는 유지)

remove

-선택한 요소를 요소에서 제거(데이터와 이벤트는 삭제)

 

아래 예제을 보면

detach을 사용한 버튼 이벤트의 p 태그 클릭 이벤트는  버튼을 클릭해도 이벤트가 유지하고 있지만

remove을 사용한 버튼 이벤트의 p 태그는 버튼을 클릭하면 p 태그의 클릭 이벤트도 같이 사라진다.

 

See the Pen detach() and remove() by onion (@saetmlda) on CodePen.

 

참고 사이트 : api.jquery.com/remove/

 

.remove() | jQuery API Documentation

Description: Remove the set of matched elements from the DOM. Similar to .empty(), the .remove() method takes elements out of the DOM. Use .remove() when you want to remove the element itself, as well as everything inside it. In addition to the elements th

api.jquery.com

 

 

 

'jquery' 카테고리의 다른 글

[jquery] after 와 insertAfter / before 와 insertBefore  (0) 2021.01.10
[jquery] append/appendTo 와 prepend/prependTo  (0) 2021.01.10
[jquery] wrap() 와 wrapAll()  (0) 2021.01.10
[jquery]clone 요소 복사  (0) 2021.01.10
[jquery] 요소 찾기  (0) 2021.01.10

댓글