Element: select event

select 이벤트는 어떤 텍스트가 선택되었을 때 발생됩니다.

Bubbles Yes
Cancelable No
Interface 유저 인터페이스로부터 발생된 경우 UIEvent (en-US), 아니라면 Event
Event handler property onselect (en-US)

The event is not available for all elements in all languages. For example, in HTML, select events can be dispatched only on form <input type="text"> (en-US) and <textarea> elements.

Examples

Selection logger

<input value="Try selecting some text in this element.">
<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 = `You selected: ${selection}`;
}

const input = document.querySelector('input');
input.addEventListener('select', logSelection);

onselect equivalent

You can also set up the event handler using the onselect (en-US) property:

input.onselect = logSelection;

Specifications

Specification Status
UI Events
The definition of 'select' in that specification.
Working Draft

Browser compatibility

BCD tables only load in the browser