A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.cdn.mozilla.net/ja/docs/Web/API/HTMLTextAreaElement/select_event below:

HTMLTextAreaElement: select イベント - Web API

HTMLTextAreaElement: select イベント

Baseline Widely available

select イベントは、テキストが選択されたときに発生します。

構文

このイベント名を addEventListener() などのメソッドで使用するか、イベントハンドラープロパティを設定するかしてください。

addEventListener("select", (event) => { })

onselect = (event) => { }
イベント型

一般的な Event です。

例 選択のログ
<textarea>この要素内のテキストを選択してみてください。</textarea>
<p id="log"></p>
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 プロパティで設定することもできます。

textarea.onselect = logSelection;
仕様書 ブラウザーの互換性 関連情報

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4