.remove()
S2C Home « Manipulation « .remove()
DOM removal.
Description
The .remove()
method is used to permanantly remove the matched set from the DOM, including any descendants.
- The
.remove()
method completely removes the elements, all bound events and jQuery data associated with them. - Use the
.detach()
method if you want to retain all bound events and jQuery data associated with the detached elements, so they can be reinserted into the DOM at a later time if required. - Use the
.empty()
method when you want to completely remove all child nodes, their bound events and jQuery data associated with them.
Syntax
Signature | Description |
---|---|
.remove( [selector] ) | Permanantly remove the matched set from the DOM. |
Parameters
Parameter | Description | Type |
---|---|---|
selector | A string containing a CSS or custom jQuery selector to match elements against. | Selector |
Return
A jQuery
object containing the removed matched set.
.remove( [selector] )
ExamplesTop
Permanantly Remove the matched set from the DOM.
When the left button is pressed we remove the left image of the chicken pie.
When the right button is pressed we remove the other two images of beef and ale pie using a selector.
$(function(){
$('#btn3').on('click', function() {
console.log($('#chickenpie').remove());
$('chickenpie').remove();
});
$('#btn4').on('click', function() {
$('img').remove('.beefpie');
});
});
Related Tutorials
jQuery Intermediate Tutorials - Lesson 5 - DOM Removal & Replacement