remove() method in jQuery

remove() in jQuery

This method removes the set of matched elements from the DOM.

When removing using this method, it will remove every contents such as text, attributes even the child nodes.

It also removes events specified for the element.

Syntax

$(selector).remove([selector])

  • selector - It denotes a selector expression that filters the set of matched elements to be removed.

Example 1

Try Yourself

Example 2 - remove and return

Try Yourself

Example 3 - set of matched elements to be removed

Try Yourself

Example 4 - Difference between remove() and empty()

Try Yourself

Example 5 - Difference between remove() and detach()

Try Yourself