Monday, November 18, 2024
Google search engine
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

Recent Comments