Text.replaceWholeText

  • Revision slug: Web/API/Text.replaceWholeText
  • Revision title: Text.replaceWholeText
  • Revision id: 471681
  • Created:
  • Creator: Reachmeatshivam
  • Is current revision? Yes
  • Comment

Revision Content

{{ DomRef("Text") }}

{{ obsolete_header }}

The Text.replaceWholeText() method replaces the text of the node and all of its logically adjacent text nodes with the specified text. The replaced nodes are removed, including the current node, unless it was the recipient of the replacement text.

A {{domxref("DOMException")}} with the value NO_MODIFICATION_ERR is thrown if one of the text nodes being replaced is read only.

This method returns the text node which received the replacement text, or null if the replacement text is an empty string.  The returned node is the current node unless the current node is read only, in which case the returned node is a newly created text node of the same type which has been inserted at the location of the replacement.

Syntax

replacementNode = textnode.replaceWholeText(content) 

Example

See the example for the {{domxref("Text.wholeText")}} property.

Specifications

Specification Status Comment
{{SpecName('DOM WHATWG', '#text', 'Text')}} {{Spec2('DOM WHATWG')}} Removed from the specification.
{{SpecName('DOM3 Core', 'core.html#ID-1312295772', 'Text')}} {{Spec2('DOM3 Core')}} Initial definition.

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{CompatVersionUnknown}} [1] [2] {{CompatGeckoDesktop("1.9.1")}} [3]
Removed in {{CompatGeckoDesktop("10")}}
{{CompatVersionUnknown}} {{CompatVersionUnknown}} [1] [2] {{CompatVersionUnknown}} [4]
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatVersionUnknown}} [1] [2] {{CompatGeckoMobile("1.9.1")}} [3]
Removed in {{CompatGeckoMobile("10")}}
{{CompatVersionUnknown}} {{CompatVersionUnknown}} [1] [2] {{CompatVersionUnknown}}[4]

[1] Chromium is currently considering dropping its support.

[2] Before Chrome 30 and Opera 17, the argument wasn't mandatory, like required by the specs.

[3] Firefox's implementation of this method never supported EntityReference nodes as defined by the specification.

[4] The argument is not mandatory, though required by the spec.

See also

  • The {{domxref("Text")}} interface it belongs to.

Revision Source

<p>{{ DomRef("Text") }}</p>
<p>{{ obsolete_header }}</p>
<p>The <strong><code>Text.replaceWholeText()</code></strong> method replaces the text of the node and all of its logically adjacent text nodes with the specified text. The replaced nodes are removed, including the current node, unless it was the recipient of the replacement text.</p>
<p>A {{domxref("DOMException")}} with the value <code>NO_MODIFICATION_ERR</code> is thrown if one of the text nodes being replaced is read only.</p>
<p>This method returns the text node which received the replacement text, or <code>null</code> if the replacement text is an empty string.&nbsp; The returned node is the current node unless the current node is read only, in which case the returned node is a newly created text node of the same type which has been inserted at the location of the replacement.</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="syntaxbox">
<em>replacementNode</em> = <em>textnode</em>.replaceWholeText(content) </pre>
<h2 id="Example" name="Example">Example</h2>
<p>See the example for the {{domxref("Text.wholeText")}} property.</p>
<h2 id="Specification" name="Specification">Specifications</h2>
<table class="standard-table">
  <tbody>
    <tr>
      <th scope="col">Specification</th>
      <th scope="col">Status</th>
      <th scope="col">Comment</th>
    </tr>
    <tr>
      <td>{{SpecName('DOM WHATWG', '#text', 'Text')}}</td>
      <td>{{Spec2('DOM WHATWG')}}</td>
      <td>Removed from the specification.</td>
    </tr>
    <tr>
      <td>{{SpecName('DOM3 Core', 'core.html#ID-1312295772', 'Text')}}</td>
      <td>{{Spec2('DOM3 Core')}}</td>
      <td>Initial definition.</td>
    </tr>
  </tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{CompatibilityTable}}</p>
<div id="compat-desktop">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Chrome</th>
        <th>Firefox (Gecko)</th>
        <th>Internet Explorer</th>
        <th>Opera</th>
        <th>Safari</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>{{CompatVersionUnknown}} [1] [2]</td>
        <td>{{CompatGeckoDesktop("1.9.1")}} [3]<br />
          Removed in {{CompatGeckoDesktop("10")}}</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatVersionUnknown}} [1] [2]</td>
        <td>{{CompatVersionUnknown}} [4]</td>
      </tr>
    </tbody>
  </table>
</div>
<div id="compat-mobile">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Android</th>
        <th>Firefox Mobile (Gecko)</th>
        <th>IE Mobile</th>
        <th>Opera Mobile</th>
        <th>Safari Mobile</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>{{CompatVersionUnknown}} [1] [2]</td>
        <td>{{CompatGeckoMobile("1.9.1")}} [3]<br />
          Removed in {{CompatGeckoMobile("10")}}</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatVersionUnknown}} [1] [2]</td>
        <td>{{CompatVersionUnknown}}[4]</td>
      </tr>
    </tbody>
  </table>
</div>
<p>[1] Chromium is currently considering dropping its support.</p>
<p>[2] Before Chrome 30 and Opera 17, the argument wasn't mandatory, like required by the specs.</p>
<p>[3] Firefox's implementation of this method never supported <code>EntityReference</code> nodes as defined by the specification.</p>
<p>[4] The argument is not mandatory, though required by the spec.</p>
<h2 id="See_also">See also</h2>
<ul>
  <li>The {{domxref("Text")}} interface it belongs to.</li>
</ul>
Revert to this revision