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 July 2015.
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
Loading…