HTML oncut Attribute

HTML oncut Attribute: This attribute fires when the user cuts the content of an element. It is a Boolean type attribute. And it is supported by all HTML elements but it is possible for that element which have a contenteditable attribute set to “true”.

HTML oncut Attribute

This attribute can be applied to all the HTML elements. And there are 3 ways to cut the content of an element. They are as follows:

  • Press CTRL + X
  • Select “Cut” from the Edit menu in your browser
  • Right-click and then select the “Cut” command

Syntax: <element oncut = “script”>



Browser Support

This attribute is supported by the following browsers:

  • Chrome
  • Firefox
  • Safari
  • Opera
  • Internet Explorer

Example: for <input> element

<!DOCTYPE html>
<html>
<body>
<input type="text" oncut="myFunction()" value="Cut this text">
<p id="demo"></p>
<script>
function myFunction() {
  document.getElementById("demo").innerHTML = "You cut text!";
}
</script>
</body>
</html>

Output:

HTML oncut attribute

Example: for <p> element

<!DOCTYPE html>
<html>
<body>
<p contenteditable="true" oncut="myFunction()">Try to cut this text</p>
<script>
function myFunction() {
  alert("You cut text!");
}
</script>
</body>
</html>

Output:

Try to cut this text