Skip to content
Related Articles

Related Articles

Improve Article

HTML DOM createRange() Method

  • Last Updated : 29 Jul, 2020

The createRange() method creates a new Range object for the document.


range = document.createRange();

Parameters: This method does not accept any parameters.

Return Value: This method returns the created Range.

Example: In this example, we will create a range using this method, a range should not be empty, so we will make starting and ending points in the range using setEnd() and setStart() method.


<!DOCTYPE html>
    <p id="parent">
        Child 1<br>
        Child 2<br>
        const example = document.getElementById('parent');
        const range = document.createRange();
        range.setStart(example, 0);
        range.setEnd(example, 3);

Output: In console, created range can be seen.

Supported Browsers:

  • Google Chrome
  • Edge
  • Firefox
  • Safari
  • Opera

Attention reader! Don’t stop learning now. Get hold of all the important Comcompetitivepetitve Programming concepts with the Web Design for Beginners | HTML  course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :