Monday, May 25, 2026
HomeLanguagesJavascriptHTML DOM Range selectNode() method

HTML DOM Range selectNode() method

The selectNode() method sets the Range content to contain the Node. The start and end of the Range will be the same as the referenceNode.

Syntax:

range.selectNode(referenceNode);

Parameters:

  • referenceNode: The Node which sets the Range content.

Return Value: This method has no return value.

Example: This example shows how to set the content of the range using this method. For better clarification, the console logged the new range content in string text by the toString() method.

HTML




<!DOCTYPE html>
<html lang="en">
 
<head>
    <title>
          HTML DOM range selectNode() method
      </title>
</head>
 
<body>
  <h1>neveropen</h1>
  <p>This is the Range Content</p>
 
    <script>
        let range = document.createRange();
        let referenceNode =
            document.getElementsByTagName('p').item(0);
        range.selectNode(referenceNode);
        console.log(range);
        console.log(range.toString());
    </script>
   
</body>
 
</html>


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

Supported Browsers: 

  • Google Chrome 1
  • Edge 12
  • Firefox 1
  • Safari 1
  • Opera 9
  • Internet Explorer 9
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

3 COMMENTS

Most Popular

Dominic
32514 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6892 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12107 POSTS0 COMMENTS
Shaida Kate Naidoo
7016 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6975 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS