Skip to content
Related Articles

Related Articles

Improve Article

HTML | DOM oncut Event

  • Last Updated : 30 Jul, 2021
Geek Week

The HTML DOM oncut Event occurs when the content of an element is cut by the user. The oncut event is mostly used on elements with type=”text”.
Supported Tags

  • It supports all HTML elements.

Syntax:
In HTML: 
 

<element oncut="myScript">

In JavaScript: 
 

object.oncut = function(){myScript};

In JavaScript, using the addEventListener() method: 
 

object.addEventListener("cut", myScript);

Note: There are three ways to cut the content of an element: 
 



  1. Press CTRL + X
  2. Select “Cut” from the Edit menu in your browser
  3. Right click to display the context menu and select the “Cut” command

Example 1: Using HTML 
 

html




<!DOCTYPE html>
<html>
 
<head>
    <title>HTML DOM oncut Event</title>
</head>
 
<body>
    <center>
        <h1 style="color:green">
          GeeksforGeeks
      </h1>
        <h2>HTML DOM oncut Event</h2>
        <input type="text"
               oncut="myFunction()"
               value="Cut the text">
 
        <p id="demo"></p>
 
 
        <script>
            function myFunction() {
                document.getElementById(
                  "demo").innerHTML = "Done";
            }
        </script>
    </center>
</body>
 
</html>

Output: 
Before: 
 

After: 
 

Example 2: Using JavaScript 
 

html




<!DOCTYPE html>
<html>
 
<head>
    <title>HTML DOM oncut Event</title>
</head>
 
<body>
    <center>
        <h1 style="color:green">
          GeeksforGeeks
      </h1>
        <h2>HTML DOM oncut Event</h2>
        <input type="text"
               id="myInput"
               value="Cut the text">
 
        <script>
            document.getElementById("myInput").oncut = function() {
                GFGfun()
            };
 
            function GFGfun() {
                alert("Done");
            }
        </script>
    </center>
</body>
 
</html>

Output: 
Before: 
 



After: 
 

Example 3: In JavaScript, using the addEventListener() method: 
 

html




<!DOCTYPE html>
<html>
 
<head>
    <title>HTML DOM oncut Event</title>
</head>
 
<body>
    <center>
        <h1 style="color:green">
          GeeksforGeeks
      </h1>
        <h2>HTML DOM oncut Event</h2>
        <input type="text"
               id="myInput"
               value="Cut the text">
 
        <script>
            document.getElementById(
              "myInput").addEventListener(
              "cut", GFGfun);
 
            function GFGfun() {
                alert("Done");
            }
        </script>
    </center>
</body>
 
</html>

Output: 
Before: 
 

After: 
 

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

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

 

Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :