onpasteEvent
Examples
Execute JavaScript when pasting text on an <input> element:
Try it Yourself »
More examples can be found at the bottom of this article.
Definition and Usage
The onpaste event is triggered when the user pastes text into an element.
Note:Although the HTML elements used all support the onpaste event, not all elements actually support it, such as the <p> element, unless contenteditable is set to "true" (see more examples below).
Tip:The onpaste event is usually used for <input> elements with type="text".
Tip:There are three ways to paste content into an element:
- Press CTRL + V
- Select "Paste" from the browser's edit menu
- Right-click the mouse button and select the "Paste" command from the context menu.
Browser Support
| Event | |||||
|---|---|---|---|---|---|
| onpaste | Yes | Yes | Yes | Yes | Yes |
Syntax
In HTML:
In JavaScript:
In JavaScript, using the addEventListener() method:
Note:Internet Explorer 8 and earlier IE versions do not supportaddEventListener()method.
Technical Details
| Bubbles: | Yes |
|---|---|
| Cancelable: | Yes |
| Event type: | ClipboardEvent |
| Supported HTML tags: | All HTML elements |

More Examples
Example
Execute JavaScript when text is pasted onto a <p> element (note contenteditable is set to "true"):
Try it Yourself »
Related Pages
HTML DOM Reference:oncopy event
HTML DOM Reference:oncut event
Event Object Other Extensions