--- title: 'Element: select event' slug: Web/API/Element/select_event translation_of: Web/API/Element/select_event ---
select
이벤트는 어떤 텍스트가 선택되었을 때 발생됩니다.
Bubbles | Yes |
---|---|
Cancelable | No |
Interface | 유저 인터페이스로부터 발생된 경우 {{domxref("UIEvent")}}, 아니라면 {{domxref("Event")}} |
Event handler property | {{domxref("GlobalEventHandlers.onselect", "onselect")}} |
The event is not available for all elements in all languages. For example, in HTML, select
events can be dispatched only on form {{HtmlElement('input/text', '<input type="text">')}}
and {{HtmlElement("textarea")}} elements.
<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);
{{EmbedLiveSample("Selection_logger")}}
You can also set up the event handler using the {{domxref("GlobalEventHandlers.onselect", "onselect")}} property:
input.onselect = logSelection;
Specification | Status |
---|---|
{{SpecName('UI Events', '#event-type-select', 'select')}} | {{Spec2('UI Events')}} |
{{Compat("api.Element.select_event")}}