Open In App

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:

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.




<!DOCTYPE html>
<html lang="en">
 
<head>
    <title>
          HTML DOM range selectNode() method
      </title>
</head>
 
<body>
  <h1>GeeksforGeeks</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: 

Article Tags :