Onpaste event

Onpaste event The event object

Perform JavaScript when pasting text on an element:

"text" onpaste" "myFunction() " value" "Try to paste the text here"

Try it out . . .

More examples can be viewed at the bottom of this article.


Definitions and usages

The onpaste event is triggered when the user pastes text into the element.

Note: Although the HTML elements used support the onpaste event, they do not actually support all elements, such as the .lt;p> element, unless contenteditable is set to "true" (see more instances below).

Tip: The onpaste event is typically used for the type-"text" element of the .lt;input>

Tip: There are three ways to paste content in an element:

  • Press CTRL and V
  • Select Paste from the browser's edit menu
  • Right-click the mouse button to select the Paste command in the context menu.

Browser support

Event
onpaste Yes Yes Yes Yes Yes


Grammar

In HTML:

< element onpaste=" myScript "> Give it a try

In JavaScript:

object .onpaste=function(){ myScript }; Give it a try

In JavaScript, use the addEventListener() method:

object .addEventListener("paste", myScript ); Give it a try

Note: The addEventListener() method is not supported in Internet Explorer 8 and earlier versions of IE.


Technical details
Whether to support bubbling: Yes
Can I cancel: Yes
Types of events: ClipboardEvent
Supported HTML tags: All HTML elements


Onpaste event

More instances

JavaScript is executed when the text content is pasted on the element (note that contenteditable is set to "true"):

Try to paste content in a paragraph. </p>

Try it out . . .


Related pages

HTML DOM Reference Manual: Oncopy Events

HTML DOM Reference Manual: Oncut Events


Onpaste event The event object