onpaste Event
Example
Call a function when pasting some text in an <input> element:
<input type="text" onpaste="myFunction()" value="Paste something here">
Try it Yourself »
More examples below
Description
The onpaste
event occurs when the user pastes some content into an element.
The onpaste
event is mostly used on <input> elements with type="text".
Note
It is only possible to paste something into an input field.
It is not possible to paste content into, for example a <p> element, UNLESS the element has set contenteditable to "true" (See "More Examples" below).
3 Ways to Paste:
- Press Ctrl + V
- Select "Paste" from the Edit menu in your browser
- Right click to display the context menu, and select "Paste"
Clipboard Events
Event | Occurs When |
---|---|
copy | The user copies content |
cut | The user starts cuts content |
paste | The user pastes content |
See Also:
Syntax
In JavaScript, using the addEventListener() method:
object.addEventListener("paste", myScript);
Try it Yourself »
Technical Details
Bubbles: | Yes |
---|---|
Cancelable: | Yes |
Event type: | ClipboardEvent |
HTML tags: | All HTML elements |
More Examples
Example
Call a function when pasting some text in a <p> element.
(Note that contenteditable is set to "true"):
<p contenteditable="true" onpaste="myFunction()">Try to paste something inside this paragraph.</p>
Try it Yourself »
Browser Support
onpaste
is a DOM Level 3 (2004) feature.
It is fully supported in all modern browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 11 |
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.