The Remove () and detach () methods all remove all elements from the DOM
What's common is that none of the matching elements are removed from the jquery object.
The difference is that the element removed with remove (), except that the element is preserved, the other binding events on the element are removed, but the detach () method does not remove the method on the element or append data.
Simple example:
Html:
<body><p> difference </p></body>
Js:
The binding event of the P element $ ("P"). Click (function () {alert ("Remove vs Detach")});
var a=$ ("P"). Remove () A is a jquery object that removes the P element when it re-plugs the retained P element back into the body of $ ("body"). HTML (a[0]), and when you click on the P element, the Click event is not triggered. That is, the event has been removed by the remove event.
var b=$ ("P"). Detach () A is a jquery object that deletes the P element when it re-plugs the retained P element back into the body of $ ("body"). HTML (a[0]), which triggers the Click event when the P element is clicked again. That is, the event remains on the element, and the detach event does not remove the P-element event.
The difference between remove () and detach () in jquery