The selectNodeContents() method sets the Range that contain the contents of a Node.
The startOffset is 0 every time, and the endOffset can be the number of child Nodes or number of characters contained in the reference Node.
Syntax:
range.selectNodeContents(referenceNode);
Parameters:
- referenceNode : The Node whose contents will set 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 of the example , console logged the range content in string text by toString() method.
HTML
<!DOCTYPE html>
< html >
< head >
< title >
HTML DOM range selectNodeContents() method
</ title >
</ head >
< body >
< h1 >GeeksforGeeks</ h1 >
< div >This is the Range Content</ div >
< script >
var range;
range = document.createRange();
range.selectNodeContents(
document.getElementsByTagName("div")[0]);
console.log(range);
console.log(range.toString());
</ script >
</ body >
</ html >
|
Output: In console, range can be seen.

Supported Browsers: The browsers supported by DOM selectNodeContents() method are listed below:
- 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,
GeeksforGeeks 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!
Last Updated :
12 Jul, 2022
Like Article
Save Article