Open In App

HTML onpaste Event Attribute

The onpaste attribute works when some content is pasted 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 HTML elements which are listed below: 

Syntax: 

<element onpaste = "script">

Attribute Value

The script event runs when the onpaste attribute is called.



Example 1:

In this example, we will see the implementation of the above event attribute. 




<!DOCTYPE html>
<html>
 
<head>
    <title>onpaste attribute</title>
    <style>
        body {
            text-align: center;
        }
 
        h1 {
            color: green;
        }
 
        input {
            padding: 20px;
        }
    </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: 



Output

Example 2 :

In this example, we will see the implementation of the above event attribute. 




<!DOCTYPE html>
<html>
 
<head>
    <title>onpaste attribute</title>
    <style>
        body {
            text-align: center;
        }
 
        h1 {
            color: green;
        }
 
        input {
            padding: 20px;
        }
    </style>
</head>
 
<body>
    <h1>GeeksforGeeks</h1>
    <h2>onpaste Attribute</h2>
    <input type="text" onpaste="Geeks()"
           value="A computer science portal for geeks"
           size="40">
 
    <script>
        function Geeks() {
            alert("pasted text!");
        }
    </script>
</body>
 
</html>

Output:

Output

Supported Tags:

It supports all HTML elements. 

Supported Browsers


Article Tags :