InputEvent: dataTransfer property
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.
ThedataTransfer read-only property of theInputEvent interface returns aDataTransfer objectcontaining information about richtext or plaintext data being added to or removed fromeditable content.
In this article
Value
ADataTransfer object ornull. The spec has anoverview of its value in various cases.
Examples
In the following simple example we've set up an event listener on theinput event so that when anycontent is pasted into the contenteditable<p> element, its HTML sourceis retrieved via theInputEvent.dataTransfer.getData()method and reported in the paragraph below the input.
Try copying and pasting some of the content provided to see the effects.
<p><span>Whoa, bold blue text!</span></p><p> <span>Exciting: italic red text!</span></p><p>Boring normal text ;-(</p><hr /><p contenteditable="true"> Go on, try pasting some content into this editable paragraph and see what happens!</p><p></p>const editable = document.querySelector("p[contenteditable]");const result = document.querySelector(".result");editable.addEventListener("input", (e) => { result.textContent = e.dataTransfer.getData("text/html");});Specifications
| Specification |
|---|
| Input Events Level 2> # dom-inputevent-datatransfer> |