- HTMLInputElement.setSelectionRange(): The HTMLInputElement.setSelectionRange() is a method that sets the start and end positions of the current text selection in an <input> or <textarea> element.
- Element.createTextRange(): It provides us with a selected text range in an input form. A caret is also known as a text cursor which is an indicator on the screen to indicate where the text is to be inserted.
- TextRange.collapse(): It helps to move the caret to the beginning or end of the current range.
- TextRange.moveEnd(): It helps to move the end of the range by a specified number of units.
- TextRange.moveStart(): It moves the start of the range by a specified number of units.
- Before clicking the button:
- After clicking the button: