HTML | onpaste Event Attribute
The onpaste attribute works when some content are paste in an element. This event attribute is supported by all HTML elements. It is mostly used with <input> element.
There are three ways to paste the content in an HTML elements which are listed below:
- Use CTRL + V key
- Select “Paste” from the edit menu in browser.
- select the “Paste” command from right click menu
Syntax:
<element onpaste = "script">
Attribute Value: The script event run when onpaste attribute is called.
Example:
<!DOCTYPE html> <html> <head> <title>onpaste attribute</title> <style> body { text-align:center; } h1 { color:green; } </style> </head> <body> <h1>GeeksforGeeks</h1> <h2>onpaste Attribute</h2> <input type="text" onpaste="Geeks()" value="A computer science portal for geeks" size="40"> <p id="sudo"></p> <script> function Geeks() { document.getElementById("sudo").innerHTML = "pasted text!"; } </script> </body> </html> |
Output:

Supported Browsers: The browser supported by onpaste attribute are listed below:
- Apple Safari
- Google Chrome
- Firefox
- Opera
- Internet Explorer
Recommended Posts:
- HTML | DOM onpaste Event
- HTML | onkeydown Event Attribute
- HTML | onresize Event Attribute
- HTML | ondragstart Event Attribute
- HTML | ondrop Event Attribute
- HTML | onkeyup Event Attribute
- HTML | ontoggle Event Attribute
- HTML | onhashchange Event Attribute
- HTML | onmouseover Event Attribute
- HTML | oninvalid Event Attribute
- HTML | ononline Event Attribute
- HTML | onsubmit Event Attribute
- HTML | onclick Event Attribute
- HTML | onmouseout Event Attribute
- HTML | ondragenter Event Attribute
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



