Computer >> Computer tutorials >  >> Programming >> HTML

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


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>