DOM Properties
HTMLTextAreaElement.selectionStart
Read/write. Returns the start offset of the selected text in UTF-16 code units, or the caret offset for a collapsed range. Use selectionEnd with it to extract selected text. The property does not itself force focus. Example result: ell.
Formal Syntax & Structure
html syntaxhtml
element.selectionStartReturn Value
number
Property value. Read/write.
Working Example
Example Snippethtml
<textarea id="demo">Hello</textarea><p>Result: <output id="result"></output></p><script>const e = document.getElementById('demo');const result = value => { document.getElementById("result").textContent = String(value); };e.setSelectionRange(1,4); result(e.value.slice(e.selectionStart,e.selectionEnd));</script>