Onpaste event
Perform JavaScript when pasting text on an element:
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:
In JavaScript:
In JavaScript, use the addEventListener() method:
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 |
More instances
JavaScript is executed when the text content is pasted on the element (note that contenteditable is set to "true"):
Try it out . . .
Related pages
HTML DOM Reference Manual: Oncopy Events
HTML DOM Reference Manual: Oncut Events
The event object