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.


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

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

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

         function display() {
            document.getElementById("test").innerHTML = "Your pasted text worked!";
Updated on 03-Mar-2020 11:27:51