Execute a script when the user pastes some content in an element in HTML?

HTMLWeb DevelopmentFront End Technology

When the user pastes the elements' text, the onpaste attribute triggers in HTML.

Example

You can try to run the following code to implement the pastes attribute −

<!DOCTYPE html>
<html>
   <body>
      <input type = "text" onpaste = "display()" value = "Paste text here">

      <h2 id = "test">Try to paste any text.</h2>

      <script>
         function display() {
            document.getElementById("test").innerHTML = "Your pasted text worked!";
         }
      </script>
   </body>
</html>
raja
Published on 14-Mar-2018 11:02:00
Advertisements