``` More examples"> ``` More examples" />
Easy Tutorial
❮ Prop Style Borderbottomstyle Prop Video Played ❯

onpaste Event

Event Object

Example

Execute JavaScript when text is pasted into an <input> element:

<input type="text" onpaste="myFunction()" value="Try pasting text here">

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 onpaste event is supported by all HTML elements, it is not actually supported by all elements, such as <p> elements, unless contenteditable is set to "true" (see more examples below).

Tip: The onpaste event is commonly used with <input> elements of type="text".

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


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 versions do not support the addEventListener() method.


Bubbles: Yes
Cancelable: Yes
--- ---
Event type: ClipboardEvent
--- ---
Supported HTML tags: All HTML elements
--- ---

More Examples

Example

Execute JavaScript when text is pasted into a <p> element (note contenteditable set to "true"):

<p contenteditable="true" onpaste="myFunction()">Try pasting content into this paragraph.</p>

Related Pages

HTML DOM Reference: oncopy Event

HTML DOM Reference: oncut Event

❮ Prop Style Borderbottomstyle Prop Video Played ❯