Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. InputEvent
  4. dataTransfer

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.

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.

html
<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>
js
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

Browser compatibility

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp