CKTIS / JavaScript
HTMLTextAreaElement.selectionEnd — selection end
HTMLTextAreaElement.selectionEnd reads or sets the ending boundary of a textarea selection. It is a zero-based offset measured in UTF-16 code units; the ending position is excluded from the selection.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
textarea.selectionEnd
textarea.selectionEnd = endHTMLTextAreaElement.selectionEnd is a read/write property. It identifies the position immediately after the selected text in textarea.value. selectionStart and selectionEnd describe an inclusive start and an exclusive end. With no selection, both values represent the caret position.
Offsets count UTF-16 code units, not visible characters: some emoji occupy two units. For textarea, the API uses the value with normalized line endings rather than raw text containing CR.
Assignment changes the selection boundary, not the text. Web IDL first converts the assigned value to an unsigned long. If the converted value exceeds the text length, it is clamped to that length. For example, 2 ** 32 converts to 0, so assigning it sets the end to 0, not to the length of a nonempty textarea. If the new end precedes selectionStart, the start also moves to the new end, collapsing the selection. Use setSelectionRange(start, end) to set both boundaries together.
Selection state exists even for an element that is not rendered, so the example does not attach the control to the document. This is a browser API defined by the HTML Standard, not an ECMAScript language feature; having Node 24 does not establish its availability.
Examples
const textarea = document.createElement('textarea');
textarea.value = 'Hello world';
textarea.setSelectionRange(0, 5);
console.log(textarea.selectionEnd);
console.log(textarea.value.slice(textarea.selectionStart, textarea.selectionEnd));
textarea.selectionEnd = 3;
console.log(textarea.value.slice(textarea.selectionStart, textarea.selectionEnd));Result
5 Hello Hel
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.