Back to Content

CharacterData: remove() method

files/en-us/web/api/characterdata/remove/index.md

latest750 B
Original Source

{{APIRef("DOM")}}

The remove() method of the {{domxref("CharacterData")}} removes it from its parent node. If it has no parent node, calling remove() does nothing.

Syntax

js-nolint
remove()

Parameters

None.

Return value

None ({{jsxref("undefined")}}).

Example

Using remove()

html
<span>Result: </span>A long string.
js
const span = document.querySelector("span");
const textNode = span.nextSibling;

textNode.remove(); // Removes the text

{{EmbedLiveSample("Example", "100%", 50)}}

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also

  • {{domxref("CharacterData.deleteData()")}}
  • {{domxref("DocumentType.remove()")}}
  • {{domxref("Element.remove()")}}