Get to know MDN better
このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
selectionStart は HTMLTextAreaElement インターフェイスのプロパティで、 <textarea> 要素内における現在のテキスト選択範囲の先頭の位置を指定します。これは、選択されたテキストの最初のインデックスを表す数値です。 <textarea> の選択されたテキストの最初のインデックスを取得したり、設定したりする際に使用することができます。
何も選択されていない場合、 selectionStart および selectionEnd の値は、どちらも <textarea> 要素内のカーソル(キャレット)の位置になります。
selectionStart を現在の selectionEnd の値より大きな値に設定すると、selectionStart と selectionEnd の両方のプロパティがその値に更新されます。 どちらの値も textLength 以上の場合、両方のプロパティが textLength プロパティの値に設定されます。
このプロパティ値は、この <textarea> にフォーカスがなくても取得したり設定したりすることができますが、要素にフォーカスがないと、 ::selection 擬似要素が選択テキストと一致しません。
selectionStart を新しい値に設定すると、 selectchange および select イベントが発生します。
非負の数値です。
| HTML # dom-textarea/input-selectionstart |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2024年11月8日 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.