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