HTML | DOM setRangeText() method
The setRangeText() method replaces a range of text in input or a textarea with another string.
Syntax:
element.setRangeText(replacement);
OR
element.setRangeText(replacement, start, end[, Mode]);
Parameters:
- select: This will select the newly inserted text.
- start: It will move the selected text before the newly inserted text.
- end: Similar to start just move the selected text after the inserted text.
- preserve: Preserve the selection and its default.
Example:
<!DOCTYPE html> <html> <head> <title> DOM focus() Method </title> <style> a:focus { background-color: magenta; } </style> </head> <body> <center> <h1 style="color:green;"> GeeksforGeeks </h1> <h2>DOM select() Method</h2> <input type="text" id="text-box" size="40" value="A online Computer Science Portal."> <button onclick="selectText()"> Update text </button> <script> //Main function function selectText() { const select = document.getElementById('text-box'); select.focus(); select.setRangeText (' For Geeks.', 32, 40, 'select'); } </script> </center> </body> </html> |
chevron_right
filter_none
Output :
Before clicking the Update button:

After clicking Update button.

Supported Browsers: The supported browsers by HTML | DOM setRangeText() method are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
Recommended Posts:
- HTML | DOM contains() Method
- HTML | DOM fullscreenEnabled() Method
- HTML | DOM execCommand() Method
- HTML | DOM getBoundingClientRect() Method
- HTML | DOM getAttribute() Method
- HTML | DOM appendChild() Method
- HTML | DOM hasFocus() Method
- HTML | DOM console.log() Method
- HTML | DOM isEqualNode() Method
- HTML | DOM removeNamedItem() Method
- HTML | DOM Select add Method
- HTML | DOM setAttributeNode() Method
- HTML | DOM removeAttribute() Method
- HTML | DOM adoptNode() Method
- HTML | DOM getAttributeNode() Method
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.



