HTMLTextAreaElement: select イベント
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.
select
イベントは、テキストが選択されたときに発生します。
構文
このイベント名を addEventListener()
などのメソッドで使用するか、イベントハンドラープロパティを設定するかしてください。
js
addEventListener("select", (event) => {});
onselect = (event) => {};
イベント型
一般的な Event
です。
例
選択のログ
html
<textarea>この要素内のテキストを選択してみてください。</textarea>
<p id="log"></p>
js
function logSelection(event) {
const log = document.getElementById("log");
const selection = event.target.value.substring(
event.target.selectionStart,
event.target.selectionEnd,
);
log.textContent = `選択範囲: ${selection}`;
}
const textarea = document.querySelector("textarea");
textarea.addEventListener("select", logSelection);
onselect による同等の処理
イベントハンドラーを onselect
プロパティで設定することもできます。
js
textarea.onselect = logSelection;
仕様書
Specification |
---|
HTML # event-select |
HTML # handler-onselect |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
select event |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.