Sunday, February 22, 2026
HomeLanguagesJavascriptHTML DOM Range setStartBefore() Method

HTML DOM Range setStartBefore() Method

The HTML DOM Range setStartBefore() method is used to set the starting position of a Range. An element that is used to set the starting point range is referenceNode element. In this method, the reference element is also included in the range.

Syntax:

range.setStartBefore( refNode );

Parameters:

  • refNode: The Node that sets the starting position of the range.

Return Value: This method does not return any value.

Example: This example describes how to set the starting of the range. Also in this example, we have used setEndAfter() method to set the ending of the range. The start reference node is the first <i> element of the document.

HTML




<!DOCTYPE html>
<html>
  
<body>
    <h1>neveropen</h1>
  
    The range will start from 1st 
    element in italics <i> RangeStart</i> 
    and end at 2nd italics element
    <i>RangeEnd</i>
  
    <script>
        var range = document.createRange();
        var refNode1 = document
            .getElementsByTagName("i").item(0);
  
        var refNode2 = document
            .getElementsByTagName("i").item(1);
              
        range.setStartBefore(refNode1);
        range.setEndAfter(refNode2);
        console.log(range);
    </script>
</body>
  
</html>


Output: In console, the created range can be seen.

Supported Browsers: 

  • Google Chrome
  • Edge
  • Firefox
  • Safari
  • Opera
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32506 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6882 POSTS0 COMMENTS
Nicole Veronica
12005 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12099 POSTS0 COMMENTS
Shaida Kate Naidoo
7011 POSTS0 COMMENTS
Ted Musemwa
7255 POSTS0 COMMENTS
Thapelo Manthata
6967 POSTS0 COMMENTS
Umr Jansen
6956 POSTS0 COMMENTS