Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1121481 of Text

  • Revision slug: Web/API/Text
  • Revision title: Text
  • Revision id: 1121481
  • Created:
  • Creator: jpmedley
  • Is current revision? Yes
  • Comment
Tags: 

Revision Content

{{ ApiRef("DOM") }}

The Text interface represents the textual content of {{domxref("Element")}} or {{domxref("Attr")}}.  If an element has no markup within its content, it has a single child implementing Text that contains the element's text.  However, if the element contains markup, it is parsed into information items and Text nodes that form its children.

New documents have a single Text node for each block of text. Over time, more Text nodes may be created as the document's content changes.  The {{domxref("Node.normalize()")}} method merges adjacent Text objects back into a single node for each block of text.

Constructor

{{domxref("Text.Text", "Text()")}} {{experimental_inline}}
Returns a Text node with the parameter as its textual content.

Properties

{{domxref("Text.isElementContentWhitespace")}} {{readonlyInline}}{{ obsolete_inline() }}

Returns a {{domxref("Boolean")}} flag indicating whether or not the text node contains only whitespace.

{{domxref("Text.wholeText")}} {{readonlyInline}}
Returns a {{domxref("DOMString")}} containing the text of all Text nodes logically adjacent to this {{domxref("Node")}}, concatenated in document order.
{{domxref("Text.assignedSlot")}} {{readonlyinline}}
Returns the {{domxref("HTMLSlotElement")}} object associated with the element.

Methods

{{domxref("Text.replaceWholeText")}} {{ obsolete_inline() }}
Replaces the text of the current node and all logically adjacent nodes with the specified text.
{{domxref("Text.splitText")}}
Breaks the node into two nodes at a specified offset.

Specifications

Specification Status Comment
{{SpecName('DOM WHATWG', '#text', 'Text')}} {{Spec2('DOM WHATWG')}} Removed the isElementContentWhitespace property.
Removed the replaceWholeText() method.
Added the Text() constructor.
{{SpecName('DOM3 Core', 'core.html#ID-1312295772', 'Text')}} {{Spec2('DOM3 Core')}} Added the isElementContentWhitespace and wholeText properties.
Added the replaceWholeText() method.
{{SpecName('DOM2 Core', 'core.html#ID-1312295772', 'Text')}} {{Spec2('DOM2 Core')}} No change from {{SpecName('DOM1')}}.
{{SpecName('DOM1', 'level-one-core.html#ID-1312295772', 'Text')}} {{Spec2('DOM1')}} Initial definition.
{{SpecName('Shadow DOM','#widl-Text-assignedSlot','assignedSlot')}} {{Spec2('Shadow DOM')}} Initial definition.

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 [3] {{CompatGeckoDesktop("1.0")}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} [3] {{CompatVersionUnknown}} [4]
wholeText 1.0 {{CompatGeckoDesktop("1.9.1")}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}
isElementContentWhitespace {{CompatNo}} {{CompatVersionUnknown}}
Removed in {{CompatGeckoDesktop("10")}}
{{CompatNo}} {{CompatNo}} {{CompatNo}}
replaceWholeText {{CompatVersionUnknown}} [1] [2] {{CompatGeckoDesktop("1.9.1")}}
Removed in {{CompatGeckoDesktop("10")}}
{{CompatVersionUnknown}} {{CompatVersionUnknown}} [1] [2] {{CompatVersionUnknown}} [4]
Text() constructor 28.0 {{CompatGeckoDesktop("24.0")}} {{CompatNo}} 15.0 {{CompatNo}}
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatVersionUnknown}} [3] {{CompatGeckoMobile("1.0")}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} [3] {{CompatVersionUnknown}} [4]
wholeText {{CompatVersionUnknown}} {{CompatGeckoMobile("1.9.1")}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}
isElementContentWhitespace {{CompatNo}} {{CompatVersionUnknown}}
Removed in {{CompatGeckoMobile("10")}}
{{CompatNo}} {{CompatNo}} {{CompatNo}}
replaceWholeText {{CompatVersionUnknown}} [1] [2] {{CompatGeckoMobile("1.9.1")}}
Removed in {{CompatGeckoMobile("10")}}
{{CompatVersionUnknown}} {{CompatVersionUnknown}} [1] [2] {{CompatVersionUnknown}} [4]
Text() constructor {{CompatVersionUnknown}} {{CompatGeckoMobile("24.0")}} {{CompatNo}} 15.0 {{CompatNo}}

[1] Chromium is currently considering dropping its support.

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

[3] Before Chrome 30 and Opera 17, splitText() argument was not mandatory, as required by the specification and implemented by IE and Gecko-based browsers.

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

See also

Revision Source

<p>{{ ApiRef("DOM") }}</p>

<p>The <strong><code>Text</code></strong> interface represents the textual content of {{domxref("Element")}} or {{domxref("Attr")}}.&nbsp; If an element has no markup within its content, it has a single child implementing <code>Text</code> that contains the element's text.&nbsp; However, if the element contains markup, it is parsed into information items and <code>Text</code> nodes that form its children.</p>

<p>New documents have a single <code>Text</code> node for each block of text. Over time, more <code>Text</code> nodes may be created as the document's content changes.&nbsp; The {{domxref("Node.normalize()")}} method merges adjacent <code>Text</code> objects back into a single node for each block of text.</p>

<h2 id="Methods" name="Methods">Constructor</h2>

<dl>
 <dt>{{domxref("Text.Text", "Text()")}} {{experimental_inline}}</dt>
 <dd>Returns a <code>Text</code> node with the parameter as its textual content.</dd>
</dl>

<h2 name="Properties">Properties</h2>

<dl>
 <dt>{{domxref("Text.isElementContentWhitespace")}} {{readonlyInline}}{{ obsolete_inline() }}</dt>
 <dd>
 <p>Returns a {{domxref("Boolean")}} flag indicating whether or not the text node contains only whitespace.</p>
 </dd>
 <dt>{{domxref("Text.wholeText")}} {{readonlyInline}}</dt>
 <dd>Returns a {{domxref("DOMString")}} containing the text of all <code>Text</code> nodes logically adjacent to this {{domxref("Node")}}, concatenated in document order.</dd>
 <dt>{{domxref("Text.assignedSlot")}} {{readonlyinline}}</dt>
 <dd>Returns the {{domxref("HTMLSlotElement")}} object associated with the element.</dd>
</dl>

<h2 id="Methods" name="Methods">Methods</h2>

<dl>
</dl>

<dl>
 <dt>{{domxref("Text.replaceWholeText")}} {{ obsolete_inline() }}</dt>
 <dd>Replaces the text of the current node and all logically adjacent nodes with the specified text.</dd>
</dl>

<dl>
 <dt><span class="internal">{{domxref("Text.splitText")}}</span></dt>
 <dd>Breaks the node into two nodes at a specified offset.</dd>
</dl>

<h2 id="Specifications">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 the <code>isElementContentWhitespace</code> property.<br />
    Removed the <code>replaceWholeText()</code> method.<br />
    Added the <code>Text()</code> constructor.</td>
  </tr>
  <tr>
   <td>{{SpecName('DOM3 Core', 'core.html#ID-1312295772', 'Text')}}</td>
   <td>{{Spec2('DOM3 Core')}}</td>
   <td>Added the <code>isElementContentWhitespace</code> and <code>wholeText</code> properties.<br />
    Added the <code>replaceWholeText()</code> method.</td>
  </tr>
  <tr>
   <td>{{SpecName('DOM2 Core', 'core.html#ID-1312295772', 'Text')}}</td>
   <td>{{Spec2('DOM2 Core')}}</td>
   <td>No change from {{SpecName('DOM1')}}.</td>
  </tr>
  <tr>
   <td>{{SpecName('DOM1', 'level-one-core.html#ID-1312295772', 'Text')}}</td>
   <td>{{Spec2('DOM1')}}</td>
   <td>Initial definition.</td>
  </tr>
  <tr>
   <td>{{SpecName('Shadow DOM','#widl-Text-assignedSlot','assignedSlot')}}</td>
   <td>{{Spec2('Shadow DOM')}}</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>1.0 [3]</td>
   <td>{{CompatGeckoDesktop("1.0")}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}} [3]</td>
   <td>{{CompatVersionUnknown}} [4]</td>
  </tr>
  <tr>
   <td><code>wholeText</code></td>
   <td>1.0</td>
   <td>{{CompatGeckoDesktop("1.9.1")}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
  <tr>
   <td><code>isElementContentWhitespace</code></td>
   <td>{{CompatNo}}</td>
   <td>{{CompatVersionUnknown}}<br />
    Removed in {{CompatGeckoDesktop("10")}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
  <tr>
   <td><code>replaceWholeText</code></td>
   <td>{{CompatVersionUnknown}} [1] [2]</td>
   <td>{{CompatGeckoDesktop("1.9.1")}}<br />
    Removed in {{CompatGeckoDesktop("10")}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}} [1] [2]</td>
   <td>{{CompatVersionUnknown}} [4]</td>
  </tr>
  <tr>
   <td><code>Text()</code> constructor</td>
   <td>28.0</td>
   <td>{{CompatGeckoDesktop("24.0")}}</td>
   <td>{{CompatNo}}</td>
   <td>15.0</td>
   <td>{{CompatNo}}</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}} [3]</td>
   <td>{{CompatGeckoMobile("1.0")}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}} [3]</td>
   <td>{{CompatVersionUnknown}} [4]</td>
  </tr>
  <tr>
   <td><code>wholeText</code></td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatGeckoMobile("1.9.1")}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
  <tr>
   <td><code>isElementContentWhitespace</code></td>
   <td>{{CompatNo}}</td>
   <td>{{CompatVersionUnknown}}<br />
    Removed in {{CompatGeckoMobile("10")}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
  <tr>
   <td><code>replaceWholeText</code></td>
   <td>{{CompatVersionUnknown}} [1] [2]</td>
   <td>{{CompatGeckoMobile("1.9.1")}}<br />
    Removed in {{CompatGeckoMobile("10")}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}} [1] [2]</td>
   <td>{{CompatVersionUnknown}} [4]</td>
  </tr>
  <tr>
   <td><code>Text()</code> constructor</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatGeckoMobile("24.0")}}</td>
   <td>{{CompatNo}}</td>
   <td>15.0</td>
   <td>{{CompatNo}}</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 specification.</p>

<p>[3] Before Chrome 30 and Opera 17, <code>splitText()</code> argument was not mandatory, as required by the specification and implemented by IE and Gecko-based browsers.</p>

<p>[4] The argument is not mandatory, though required by the spec.</p>

<h2 id="See_also">See also</h2>

<ul>
 <li><a href="/en-US/docs/DOM/DOM_Reference" title="/en-US/docs/DOM/DOM_Reference">The DOM interfaces index</a>.</li>
</ul>
Revert to this revision