Range: toString() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2017.

The Range.toString() method is a stringifier returning the text of the Range.

Syntax

js
toString()

Parameters

None.

Return value

A string.

Examples

HTML

html
<p>
  This example logs <em>everything</em> between the emphasized <em>words</em>.
  Look at the output below.
</p>
<p id="log"></p>

JavaScript

js
const range = document.createRange();

range.setStartBefore(document.getElementsByTagName("em").item(0), 0);
range.setEndAfter(document.getElementsByTagName("em").item(1), 0);
document.getElementById("log").textContent = range.toString();

Result

Specifications

Specification
DOM
# dom-range-stringifier

Browser compatibility

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
toString

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

See also