Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

HTML | DOM onpaste Event

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The HTML DOM onpaste event occurs when some content pastes in an element. this event works on every element like in <p> element if contenteditable set true then we can paste content in <p> element.
The HTML DOM onpaste event mostly used in input element type=”text”.
Supported Tags 

It supports all HTML Elements. 

Syntax: 
 

  • In HTML: 
     
<element onpaste="myScript">
  • In JavaScript: 
     
object.onpaste = function(){myScript};
  • In JavaScript, using the addEventListener() method: 
     
object.addEventListener("paste", myScript);

Example: Using the addEventListener() method. 
 

html




<!DOCTYPE html>
<html>
 
<head>
    <title>
      HTML DOM onpaste Event
  </title>
</head>
 
<body>
    <center>
        <h1 style="color:green">
          GeeksforGeeks
      </h1>
        <h2>HTML DOM onpaste Event</h2>
       
        <input type="text" id="inputID" size="37">
 
        <script>
            document.getElementById(
                "inputID").addEventListener("paste", GFGfun);
 
            function GFGfun() {
                alert("Text pasted");
            }
        </script>
    </center>
</body>
 
</html>

Output: 
 

Supported Browsers: The browsers supported by HTML DOM onpaste Event are listed below: 
 

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Apple Safari
  • Opera

 

My Personal Notes arrow_drop_up
Last Updated : 27 Jul, 2021
Like Article
Save Article
Similar Reads
Related Tutorials