Web/API/InputEvent/inputType

From Get docs


The inputType read-only property of the InputEvent interface returns the type of change made to editible content. Possible changes include for example inserting, deleting, and formatting text.

Syntax

var aString = inputEvent.inputType;

Value

A DOMString containing the type of input that was made. There are many possible values, such as insertText, deleteContentBackward, insertFromPaste, and formatBold. For a complete list of the available input types, see the Attributes section of the Input Events Level 1 spec.

Examples

This example logs the inputType for input events on an editable <div>.

HTML

<p id="log">Input type: </p>
<div contenteditable="true" style="margin: 20px;padding: 20px;border:2px dashed red;">
  <p>Some sample text. Try inserting line breaks, or deleting text in different ways, or pasting different content in.</p>
  <hr>
  <ul>
    <li>A sample</li>
    <li>bulleted</li>
    <li>list.</li>
  </ul>
  <p>Another paragraph.</p>
</div>

JavaScript

const log = document.getElementById('log');
const editable = document.querySelector('div[contenteditable]');
editable.addEventListener('input', logInputType);

function logInputType(event) {
  log.textContent = `Input type: ${event.inputType}`;
}

Result

Try editing the text inside the <div> and see what happens.

Note: See also Masayuki Nakano's InputEvent test suite for a more detailed example.


Specifications

Specification Status Comment
UI EventsThe definition of 'inputType' in that specification. Working Draft

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet

inputType

Experimental'

Chrome

Full support 60

Edge

Full support 79

Firefox

Full support 66

IE

No support No

Opera

Full support 47

Safari

Full support 10.1

WebView Android

Full support 60

Chrome Android

Full support 60

Firefox Android

Full support 66

Opera Android

Full support 44

Safari iOS

Full support 10.3

Samsung Internet Android

Full support 8.0

insertFromPasteAsQuotation input type

Experimental'

Chrome

No support No

Edge

No support No

Firefox

Full support 67

IE

No support No

Opera

No support No

Safari

?

WebView Android

No support No

Chrome Android

No support No

Firefox Android

Full support 67

Opera Android

No support No

Safari iOS

?

Samsung Internet Android

No support No

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.'
Experimental. Expect behavior to change in the future.