Skip to content
Related Articles

Related Articles

HTML DOM Range toString() Method

Improve Article
Save Article
Like Article
  • Last Updated : 08 Jul, 2020

The Range toString() method is used to convert range to String text. The selected Range is an object which need to be converted to text , so this method is used.



Parameters: This method does not accept any parameters.

Return value: This method return the string text of the specified range.

Example: This example shows how to convert a range to string text. We used setStartBefore() method and setEndAfter() method to set the range for our example.


<!DOCTYPE html>
        HTML DOM range toString() property
        The range starts from italics 
        text <b><i>RangeStart</i></b
        "This is the Range text" <b>
    Range in String Text is below: 
    <b><p id="text"></p></b>
        const range = document.createRange();
            .innerHTML = range.toString();

Output: The innerHTML of text element contains the range in text format.

For Reference, the range object and text range are logged in console for better clarification about this method.

Supported Browsers:

  • Google Chrome
  • Edge
  • Firefox
  • Apple Safari
  • Opera

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!