Saturday, September 6, 2025
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

Most Popular

Dominic
32269 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6639 POSTS0 COMMENTS
Nicole Veronica
11803 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11868 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7029 POSTS0 COMMENTS
Thapelo Manthata
6704 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS