Remove an Element Using jQuery

Опубликовано: 03 Май 2026
на канале: HighTech6839v
0

The .remove() function in jQuery is used to remove selected elements from the DOM, along with all of their child nodes, text, data, and event handlers. When .remove() is called on a jQuery object, it iterates through each element in the set and removes it from the document. The method returns the removed elements as a new jQuery object, which can be useful for further manipulation or later reinsertion into the DOM, although the removed elements are no longer connected to the original document.

After this code executes, the paragraph with the class "removable" will be completely removed from the DOM, and the .container will only contain the span element.

It's important to note that .remove() permanently deletes the elements and their associated data and events. If you need to temporarily remove an element and potentially reinsert it later while preserving its data and events, consider using the .detach() method instead.