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 GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
toString |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.