HTMLTextAreaElement: selectionEnd プロパティ
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Please help us by answering a few questions.
selectionEnd
は HTMLTextAreaElement
インターフェイスのプロパティで、 <textarea>
要素内における現在のテキスト選択範囲の末尾の位置を指定します。これは、選択されたテキストの最後のインデックスを表す数値です。 <textarea>
の選択されたテキストの末尾のインデックスを取得したり、設定したりする際に使用することができます。
何も選択されていない場合、 selectionStart
および selectionEnd
の値は、どちらも <textarea>
要素内のカーソル(キャレット)の位置になります。
selectionEnd
を現在の selectionStart
の値より小さい値に設定すると、selectionEnd
と selectionStart
の両方のプロパティがその値に更新されます。 どちらの値も 0 未満の場合、両方のプロパティが textLength
プロパティの値に設定されます。
このプロパティ値は、この <textarea>
にフォーカスがなくても取得したり設定したりすることができますが、要素にフォーカスがないと、 ::selection
擬似要素が選択テキストと一致しません。
selectionEnd
を新しい値に設定すると、 selectchange
および select
イベントが発生します。
値
非負の数値です。
例
const textarea = document.getElementById("text-box");
const end = textarea.selectionEnd;
仕様書
Specification |
---|
HTML # dom-textarea/input-selectionend |
ブラウザーの互換性
関連情報
<textarea>
HTMLTextAreaElement
HTMLTextAreaElement.selectionStart
HTMLTextAreaElement.selectionDirection
HTMLTextAreaElement.textLength
selectionChange
イベントHTMLTextAreaElement.select()
HTMLTextAreaElement.setSelectionRange()
HTMLTextAreaElement.setRangeText()
HTMLInputElement.selectionEnd
Selection
::selection
擬似要素