Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.
The TextEvent interface is a legacy UI event interface for reporting changes to text UI elements.
Note: TextEvent events have been superseded by events such as input, beforeinput, keypress, keyup, and keydown.
This interface also inherits properties from its parent UIEvent, and indirectly from Event.
TextEvent.data Read only Deprecated
Indicates the data associated with the event.
TextEvent.initTextEvent() Deprecated
Populates the values of this (new) TextEvent with the given parameters.
The following is a list of all TextEvent events:
textinputYou can register a listener for text input events using EventTarget.addEventListener() as follows:
element.addEventListener(
"textInput",
(event) => {
// …
},
false,
);
This example listens for a number of events that are fired on an input, including textInput. The event type and the event data are logged, allowing you to see where textInput is emitted relative to the other events such as those generated by key presses.
<input placeholder="Enter some text" name="name" />
const input = document.querySelector("input");
input.addEventListener("keypress", updateValue);
input.addEventListener("keyup", updateValue);
input.addEventListener("keydown", updateValue);
input.addEventListener("input", updateValue);
input.addEventListener("beforeinput", updateValue);
input.addEventListener("textInput", updateValue);
function updateValue(e) {
log(`${e.type}: ${e.data}`);
}
| Specification |
|---|
| UI Events> # legacy-textevent-events> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
TextEvent |
1 | 12 | 129 | 15 | 3 | 18 | 129 | 14 | 2 | 1.0 | 4.4 | 2 |
data |
1 | 12 | 129 | 15 | 3 | 18 | 129 | 14 | 2 | 1.0 | 4.4 | 2 |
initTextEvent |
1 | 12 | 129 | 15 | 3 | 18 | 129 | 14 | 2 | 1.0 | 4.4 | 2 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/TextEvent