The Wayback Machine - https://web.archive.org/web/20240204103730/https://www.geeksforgeeks.org/html-dom-onpaste-event/
Open In App
Related Articles

HTML DOM onpaste Event

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

The HTML DOM onpaste event occurs when some content is pasted in an element. this event works on every element like in <p> element if contenteditable set is true then we can paste content in <p> element. The HTML DOM onpaste event is 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>
    <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>
</body>
 
</html>


Output: 

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

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

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Looking for a place to share your ideas, learn, and connect? Our Community portal is just the spot! Come join us and see what all the buzz is about!


Last Updated : 15 Jun, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials