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.
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.
- Google Chrome
- Apple Safari