Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

onpaste event

onpaste event

Event Object Reference Event Object

Example

in Execute JavaScript when text is pasted onto an element:

Try it »

You can find more examples at the bottom of this article.


Definition and Usage

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

Note: Although all used HTML elements support the onpaste event, not all elements actually support it, for example

unless contenteditable is set to "true" (see more examples below).

Tip: The onpaste event is typically used for elements with type="text" .

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


Browser support

Events
onpaste Yes Yes Yes Yes Yes

Syntax

In HTML:

<

element

onpaste="

myScript

">

Try it

In JavaScript:

object

.onpaste=function(){

myScript

};

Try it

In JavaScript, use the addEventListener() method:

object

.addEventListener("paste",

myScript

);

Try it

Note: Internet Explorer 8 and earlier IE versions do not support addEventListener() method.


Technical Details

Does it support bubbling: Yes
Is it cancelable: Yes
Event type: ClipboardEvent
Supported HTML tags: All HTML elements

More examples

Example

When pasting onto the

element, execute JavaScript (note that contenteditable is set to "true"):

Try pasting content into the paragraph.

Try it »


Related pages

HTML DOM Reference Manual: oncopy event

HTML DOM Reference Manual: oncut event

Event Object Reference Event Object