instance method Element#remove

View source on GitHub →

Element#remove() → Element

Completely removes element from the document and returns it.

If you would rather just hide the element and keep it around for further use, try Element.hide instead.

Examples
// Before:
<ul>
  <li id="golden-delicious">Golden Delicious</li>
  <li id="mutsu">Mutsu</li>
  <li id="mcintosh">McIntosh</li>
  <li id="ida-red">Ida Red</li>
</ul>

And the associated JavaScript:

$('mutsu').remove();
// -> Element (and removes li#mutsu)

The resulting HTML:

<ul>
  <li id="golden-delicious">Golden Delicious</li>
  <li id="mcintosh">McIntosh</li>
  <li id="ida-red">Ida Red</li>
</ul>
Warning

Using Element.remove as an instance method (e.g., $('foo').remove('')) won't work when the element in question is a select element, sinceselect elements have an existing remove method that behaves differently from this method. As a workaround, use the generic version instead (Element.remove('foo')).

This method can be called either as an instance method or as a generic method. If calling as a generic, pass the instance in as the first argument.