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, console logged the new range content in string text by toString() method.
HTML
<html><head><title>HTML DOM range selectNode() method</title> </head><body> <h1>GeeksforGeeks</h1> <p>This is the Range Content</p></body><script> let range = document.createRange(); let referenceNode = document.getElementsByTagName('p').item(0); range.selectNode(referenceNode); console.log(range); console.log(range.toString());</script></html> |
Output: In console, range content can be seen.
Supported Browsers:
- Google Chrome
- Edge
- Firefox
- Safari
- Opera
- Internet Explorer
Recommended Posts:
- HTML DOM Range collapse() Method
- HTML DOM Range setEndAfter() Method
- HTML DOM Range setStartBefore() Method
- HTML DOM Range selectNodeContents() Method
- HTML DOM Range cloneContents() method
- HTML DOM Range setStart() Method
- HTML DOM Range setEnd() Method
- HTML DOM Range deleteContents() Method
- HTML DOM Range setEndBefore() method
- HTML DOM Range compareBoundaryPoints() method
- HTML DOM Range toString() Method
- HTML DOM Range extractContents() Method
- HTML DOM Range insertNode() Method
- HTML DOM Range cloneRange() Method
- HTML | DOM Input Range stepDown() Method
- HTML | DOM Input Range stepUp() Method
- HTML | <input type="range">
- HTML | DOM Input Range min Property
- HTML | DOM Input Range name Property
- HTML DOM Range endOffset property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


