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

Execute a script when the content of the element is being cut in HTML?


When the user cuts the elements' text, the oncut attribute triggers in HTML.

Example

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

<!DOCTYPE html>
<html>
   <body>
      <input type = "text" oncut = "display()" value = "Cut me">

      <h2 id = "test">Try to cut the above text.</h2>

      <script>
         function display() {
            document.getElementById("test").innerHTML = "Your cut text worked!";
         }
      </script>

   </body>
</html>